scripts: Add a slightly better version of the cpu load monitor
This commit is contained in:
parent
af3a4ff637
commit
3328ee7871
20
scripts/cpuload.py
Executable file
20
scripts/cpuload.py
Executable 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
3
scripts/getload.sh
Executable 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
|
Loading…
Reference in New Issue
Block a user