From 3328ee7871509d574ba8f9e05b0703596b247c91 Mon Sep 17 00:00:00 2001 From: Markus Koch Date: Mon, 15 Jan 2018 19:28:58 +0100 Subject: [PATCH] scripts: Add a slightly better version of the cpu load monitor --- scripts/cpuload.py | 20 ++++++++++++++++++++ scripts/getload.sh | 3 +++ 2 files changed, 23 insertions(+) create mode 100755 scripts/cpuload.py create mode 100755 scripts/getload.sh diff --git a/scripts/cpuload.py b/scripts/cpuload.py new file mode 100755 index 0000000..d59d892 --- /dev/null +++ b/scripts/cpuload.py @@ -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() diff --git a/scripts/getload.sh b/scripts/getload.sh new file mode 100755 index 0000000..26353da --- /dev/null +++ b/scripts/getload.sh @@ -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