scripts: Add a slightly better version of the cpu load monitor

This commit is contained in:
Markus Koch 2018-01-15 19:28:58 +01:00
parent af3a4ff637
commit 3328ee7871
2 changed files with 23 additions and 0 deletions

20
scripts/cpuload.py Executable file
View File

@ -0,0 +1,20 @@
#!/usr/bin/env python
import subprocess
import serial
ser = serial.Serial("/dev/ttyACM0")
ser.write(b'\nxx\n')
last = 0
while 1:
p = subprocess.Popen("./getload.sh", shell=True);
r = p.wait()
r = round(r / 100 * 60)
#if (r < last - 2):
# r = last - 4
last=r
ser.write(b'X')
ser.write(r.to_bytes(1, byteorder='big'))
ser.write(r.to_bytes(1, byteorder='big'))
ser.write(b'\n')
ser.close()

3
scripts/getload.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/bash
cpu=`cat <(grep 'cpu ' /proc/stat) <(sleep 0.1 && grep 'cpu ' /proc/stat) | awk -v RS="" '{print ($13-$2+$15-$4)*100/($13-$2+$15-$4+$16-$5)}' | sed "s/\..*//g"`
exit $cpu