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 GNUPLOT_VERSION_EXPECTED = 5.0
# Run a command in a running gnuplot process # Run a command in a running gnuplot process
def g(command): def g(command):
global gnuplot global gnuplot
@ -62,60 +61,61 @@ cpu_name="unknown"
labels = [] labels = []
for line in sys.stdin: with open("data.txt", "r") as f:
value = None for line in f:
value = None
if len(line) <= 0: if len(line) <= 0:
continue continue
if line[0] != '#': if line[0] != '#':
if not START_DATE: if not START_DATE:
START_DATE = scan("^(\S+)", str, line) START_DATE = scan("^(\S+)", str, line)
END_DATE = scan("^(\S+)", str, line) END_DATE = scan("^(\S+)", str, line)
value = scan("label: (.+)", str, line) value = scan("label: (.+)", str, line)
if value is not None: if value is not None:
key = scan("(\S+) label:", str, line) key = scan("(\S+) label:", str, line)
labels.append([key, value]) labels.append([key, value])
# Comments are not mixed with anything else, so skip # Comments are not mixed with anything else, so skip
continue continue
value = scan("machine: ([^,]+)", str, line) value = scan("machine: ([^,]+)", str, line)
if value is not None: if value is not None:
uname = value uname = value
value = scan("cpu count: ([^,]+)", int, line) value = scan("cpu count: ([^,]+)", int, line)
if value is not None: if value is not None:
cpus = value cpus = value
value = scan("cpu: ([^,\n]+)", str, line) value = scan("cpu: ([^,\n]+)", str, line)
if value is not None: if value is not None:
cpu_name = value cpu_name = value
value = scan("observed disk: ([^,]+)", str, line) value = scan("observed disk: ([^,]+)", str, line)
if value is not None: if value is not None:
NAME_FS = value NAME_FS = value
value = scan("total ram: (\S+)", stof, line) value = scan("total ram: (\S+)", stof, line)
if value is not None: if value is not None:
TOTAL_RAM = value TOTAL_RAM = value
value = scan("max ram used: (\S+)", stof, line) value = scan("max ram used: (\S+)", stof, line)
if value is not None: if value is not None:
MAX_USED_RAM = value MAX_USED_RAM = value
value = scan("total disk space: (\S+)", stof, line) value = scan("total disk space: (\S+)", stof, line)
if value is not None: if value is not None:
TOTAL_FS = value TOTAL_FS = value
value = scan("max disk used: (\S+)", stof, line) value = scan("max disk used: (\S+)", stof, line)
if value is not None: if value is not None:
MAX_USED_FS = value MAX_USED_FS = value
value = scan("average load: (\S+)", stof, line) value = scan("average load: (\S+)", stof, line)
if value is not None: if value is not None:
AVERAGE_LOAD = value AVERAGE_LOAD = value
# Initialize the plot # 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 sys
import time import time
# Get access to main module information
import __main__
from common import * from common import *
global die global die
@ -35,8 +38,8 @@ args = parser.parse_args()
# Handle SIGTERM # Handle SIGTERM
def kill_handler(a, b): def kill_handler(a, b):
global die global die
die = 1 die = 1
# Check if a process is running # Check if a process is running
@ -102,7 +105,7 @@ if args.session:
if cmd[0] == "start": if cmd[0] == "start":
print(f"Starting sargraph session '{sid}'") 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: while p.poll() is None:
time.sleep(0.1) time.sleep(0.1)
gpid = 0 gpid = 0
@ -286,7 +289,7 @@ with open("data.txt", "a") as f:
f"total disk space: {TOTAL_FS:.2f} GB", f"total disk space: {TOTAL_FS:.2f} GB",
f"max ram used: {MAX_USED_RAM:.2f} GB", f"max ram used: {MAX_USED_RAM:.2f} GB",
f"max disk used: {MAX_USED_FS:.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"observed disk: {FS_NAME}",
f"duration: {delta_t:.2f} minutes", f"duration: {delta_t:.2f} minutes",
sep=", ", file=f) sep=", ", file=f)

Loading…
Cancel
Save