-
Notifications
You must be signed in to change notification settings - Fork 0
/
systemLoad.py
40 lines (35 loc) · 1.09 KB
/
systemLoad.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import os
import time
import subprocess
import datetime
today = datetime.datetime.today().strftime("%d%b%Y")
outFile = f"myLoad.csv"
with open(outFile, "w") as file_csv:
file_csv.write("tTime, Time, loadAvg 1m, loadAvg 5m, loadAvg 15m\n")
wait = True
kount = 0
while wait or kount < 20:
# Current time
now = datetime.datetime.utcnow().strftime("%H:%M:%S.%f")
nowt = time.time()
# Load
load = os.getloadavg()
with open(outFile, "a") as file_csv:
file_csv.write(f"{nowt}, {now}, {load[0]}, {load[1]}, {load[2]}\n")
wait = False
command = ["ps", "fx"]
process = subprocess.Popen(command, stderr=subprocess.PIPE, stdout=subprocess.PIPE) # , universal_newlines=True)
s = process.stdout.readlines()
for proc in s:
if "create_behavioural" in proc.decode():
wait = True
kount = 0
if "download_behavioural" in proc.decode():
wait = True
kount = 0
if "test-all" in proc.decode():
wait = True
kount = 0
if not wait:
kount = kount + 1
time.sleep(10)