Browse Source

Add backwards compatible sargraph.py script

check-vt100
Aleksander Kiryk 4 years ago committed by Aleksander Kiryk
parent
commit
5a69492719
  1. 84
      graph.py
  2. 10
      sargraph.py
  3. 11
      watch.py

84
graph.py

@ -19,7 +19,6 @@ global gnuplot
GNUPLOT_VERSION_EXPECTED = 5.0
# Run a command in a running gnuplot process
def g(command):
global gnuplot
@ -62,60 +61,61 @@ cpu_name="unknown"
labels = []
for line in sys.stdin:
value = None
with open("data.txt", "r") as f:
for line in f:
value = None
if len(line) <= 0:
continue
if len(line) <= 0:
continue
if line[0] != '#':
if not START_DATE:
START_DATE = scan("^(\S+)", str, line)
END_DATE = scan("^(\S+)", str, line)
if line[0] != '#':
if not START_DATE:
START_DATE = scan("^(\S+)", str, line)
END_DATE = scan("^(\S+)", str, line)
value = scan("label: (.+)", str, line)
if value is not None:
key = scan("(\S+) label:", str, line)
labels.append([key, value])
value = scan("label: (.+)", str, line)
if value is not None:
key = scan("(\S+) label:", str, line)
labels.append([key, value])
# Comments are not mixed with anything else, so skip
continue
# Comments are not mixed with anything else, so skip
continue
value = scan("machine: ([^,]+)", str, line)
if value is not None:
uname = value
value = scan("machine: ([^,]+)", str, line)
if value is not None:
uname = value
value = scan("cpu count: ([^,]+)", int, line)
if value is not None:
cpus = value
value = scan("cpu count: ([^,]+)", int, line)
if value is not None:
cpus = value
value = scan("cpu: ([^,\n]+)", str, line)
if value is not None:
cpu_name = value
value = scan("cpu: ([^,\n]+)", str, line)
if value is not None:
cpu_name = value
value = scan("observed disk: ([^,]+)", str, line)
if value is not None:
NAME_FS = value
value = scan("observed disk: ([^,]+)", str, line)
if value is not None:
NAME_FS = value
value = scan("total ram: (\S+)", stof, line)
if value is not None:
TOTAL_RAM = value
value = scan("total ram: (\S+)", stof, line)
if value is not None:
TOTAL_RAM = value
value = scan("max ram used: (\S+)", stof, line)
if value is not None:
MAX_USED_RAM = value
value = scan("max ram used: (\S+)", stof, line)
if value is not None:
MAX_USED_RAM = value
value = scan("total disk space: (\S+)", stof, line)
if value is not None:
TOTAL_FS = value
value = scan("total disk space: (\S+)", stof, line)
if value is not None:
TOTAL_FS = value
value = scan("max disk used: (\S+)", stof, line)
if value is not None:
MAX_USED_FS = value
value = scan("max disk used: (\S+)", stof, line)
if value is not None:
MAX_USED_FS = value
value = scan("average load: (\S+)", stof, line)
if value is not None:
AVERAGE_LOAD = value
value = scan("average load: (\S+)", stof, line)
if value is not None:
AVERAGE_LOAD = value
# Initialize the plot

10
sargraph.py

@ -0,0 +1,10 @@
#!/usr/bin/env python3
#
# (c) 2019-2022 Antmicro <www.antmicro.com>
# License: Apache
#
import watch
import graph

11
watch.py

@ -17,6 +17,9 @@ import subprocess
import sys
import time
# Get access to main module information
import __main__
from common import *
global die
@ -35,8 +38,8 @@ args = parser.parse_args()
# Handle SIGTERM
def kill_handler(a, b):
global die
die = 1
global die
die = 1
# Check if a process is running
@ -102,7 +105,7 @@ if args.session:
if cmd[0] == "start":
print(f"Starting sargraph session '{sid}'")
p = subprocess.Popen(["screen", "-dmSL", sid, os.path.realpath(__file__), *sys.argv[3:]])
p = subprocess.Popen(["screen", "-dmSL", sid, os.path.realpath(__main__.__file__), *sys.argv[3:]])
while p.poll() is None:
time.sleep(0.1)
gpid = 0
@ -286,7 +289,7 @@ with open("data.txt", "a") as f:
f"total disk space: {TOTAL_FS:.2f} GB",
f"max ram used: {MAX_USED_RAM:.2f} GB",
f"max disk used: {MAX_USED_FS:.2f} GB",
f"average load: {AVERAGE_LOAD:.2f} %%",
f"average load: {AVERAGE_LOAD:.2f} %",
f"observed disk: {FS_NAME}",
f"duration: {delta_t:.2f} minutes",
sep=", ", file=f)

Loading…
Cancel
Save