From 802621a3aa0e3071adc7c03e7c37ae6ef972c3f7 Mon Sep 17 00:00:00 2001 From: RLF Date: Wed, 27 Dec 2023 01:01:04 -0500 Subject: [PATCH] added more CPU load sources and round function --- uno-stats-monitor/monitor_sender.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/uno-stats-monitor/monitor_sender.sh b/uno-stats-monitor/monitor_sender.sh index d63aa29..e871164 100644 --- a/uno-stats-monitor/monitor_sender.sh +++ b/uno-stats-monitor/monitor_sender.sh @@ -7,9 +7,16 @@ TTY="/dev/ttyACM0" ########################################################## +round() { + printf "%.${2}f" "${1}" +} + # Stats # we are limited to 2 lines and 16 chars per line so, light stats & no labels -CLOAD=$(mpstat | awk '$3 ~ /CPU/ { for(i=1;i<=NF;i++) { if ($i ~ /%idle/) field=i } } $3 ~ /all/ { printf("%d%%",100 - $field) }') +#CLOAD=$(mpstat | awk '$3 ~ /CPU/ { for(i=1;i<=NF;i++) { if ($i ~ /%idle/) field=i } } $3 ~ /all/ { printf("%d%%",100 - $field) }') +#CLOAD=$(cat <(grep 'cpu ' /proc/stat) <(sleep 1 && grep 'cpu ' /proc/stat) | awk -v RS="" '{print ($13-$2+$15-$4)*100/($13-$2+$15-$4+$16-$5)}') +CLOAD=$(awk '{u=$2+$4; t=$2+$4+$5; if (NR==1){u1=u; t1=t;} else print ($2+$4-u1) * 100 / (t-t1) "%"; }' <(grep 'cpu ' /proc/stat) <(sleep 0.5;grep 'cpu ' /proc/stat)) +CLOAD=$(round ${CLOAD} 0)% CTEMP=$(sensors | grep TSI0_TEMP: | tr '°+' ' ' | awk '{print $2}' | paste -sd ', ') MFREE=$(free -h | grep Mem | awk '{print $4}' | paste -sd ', ') RFREE=$(df -h | grep /dev/nvme0n1p3 | awk '{print $4}' | paste -sd ', ')