added more CPU load sources and round function

This commit is contained in:
RLF
2023-12-27 01:01:04 -05:00
parent 1769ebabbb
commit 802621a3aa

View File

@@ -7,9 +7,16 @@
TTY="/dev/ttyACM0" TTY="/dev/ttyACM0"
########################################################## ##########################################################
round() {
printf "%.${2}f" "${1}"
}
# Stats # Stats
# we are limited to 2 lines and 16 chars per line so, light stats & no labels # 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 ', ') CTEMP=$(sensors | grep TSI0_TEMP: | tr '°+' ' ' | awk '{print $2}' | paste -sd ', ')
MFREE=$(free -h | grep Mem | awk '{print $4}' | paste -sd ', ') MFREE=$(free -h | grep Mem | awk '{print $4}' | paste -sd ', ')
RFREE=$(df -h | grep /dev/nvme0n1p3 | awk '{print $4}' | paste -sd ', ') RFREE=$(df -h | grep /dev/nvme0n1p3 | awk '{print $4}' | paste -sd ', ')