summaryrefslogtreecommitdiffstats
path: root/core/modules/hardware-stats/data
diff options
context:
space:
mode:
authorSimon Rettberg2020-04-30 17:13:25 +0200
committerSimon Rettberg2020-04-30 17:13:25 +0200
commite449f04ea5e65e30ad1679d5640e0f6ea1ea6da5 (patch)
treec12156a5f7ae84730dbce55f6178b8554b43dbd8 /core/modules/hardware-stats/data
parentkernel.wanted.config: Add USB stuff (diff)
downloadmltk-e449f04ea5e65e30ad1679d5640e0f6ea1ea6da5.tar.gz
mltk-e449f04ea5e65e30ad1679d5640e0f6ea1ea6da5.tar.xz
mltk-e449f04ea5e65e30ad1679d5640e0f6ea1ea6da5.zip
[hardware-stats] Fix CPU load script
Diffstat (limited to 'core/modules/hardware-stats/data')
-rwxr-xr-xcore/modules/hardware-stats/data/opt/openslx/scripts/cron-system_usage_update12
1 files changed, 5 insertions, 7 deletions
diff --git a/core/modules/hardware-stats/data/opt/openslx/scripts/cron-system_usage_update b/core/modules/hardware-stats/data/opt/openslx/scripts/cron-system_usage_update
index e11a973d..c162fec4 100755
--- a/core/modules/hardware-stats/data/opt/openslx/scripts/cron-system_usage_update
+++ b/core/modules/hardware-stats/data/opt/openslx/scripts/cron-system_usage_update
@@ -47,19 +47,18 @@ if [ -n "$SLX_EXAM" ]; then
SLX_RUNMODE_MODULE="exams"
fi
# CPU temp and load
-CPU_LOAD=
-CPU_TEMP=
+set --
if $full; then
current="$( awk '$1 == "cpu" {print ($5+$6) " " ($2+$3+$4+$5+$6+$7+$8)}' /proc/stat )"
c_count=${current#* }
write=false
- if [ -s "/run/openslx/usage.update" ]; then
+ if [ -s "/run/openslx/usage.state" ]; then
old="$( cat "/run/openslx/usage.state" )"
l_count="${old#* }"
# sloppy way to prevent rapid updates; counter speed varies depending on HZ and core count
if [ "$(( c_count - l_count ))" -gt 12000 ]; then
write=true
- CPU_LOAD="$( echo "$current $old" | awk '{ print (100 - ($1 - $3)/($2 - $4) * 100) }' )"
+ set -- "$@" "--data-urlencode" "cputemp=$( echo "$current $old" | awk '{ print (100 - ($1 - $3)/($2 - $4) * 100) }' )"
fi
else
write=true
@@ -70,7 +69,7 @@ if $full; then
if command -v sensors > /dev/null; then
# TODO JSON support arrived recently, port after base system is updated from 18.04
# Try to get the package id reading, use core temps as fallback
- CPU_TEMP="$( sensors | tr 'A-Z' 'a-z' \
+ set -- "$@" "--data-urlencode" "cpuload=$( sensors | tr 'A-Z' 'a-z' \
| awk 'BEGIN{p=0;pc=0;c=0;cc=0} {if ($1 == "package" && substr($4, 1, 1) == "+") {gsub("[^0-9.]", "", $4); p += $4; pc++} if ($1 ~ /^core/ && substr($3, 1, 1) == "+") {gsub("[^0-9.]", "", $3); c += $3; cc++} } END{if (pc > 0) print (p / pc); else if (cc > 0) print (c / cc);}' )"
fi
fi
@@ -79,8 +78,7 @@ curl --retry 3 --retry-connrefused -m 6 -s --data-urlencode "type=~runstate" --d
--data-urlencode "user=$Name" --data-urlencode "tmpsize=$TMP_SIZE" --data-urlencode "tmpfree=$TMP_FREE" \
--data-urlencode "swapsize=$SWAP_SIZE" --data-urlencode "swapfree=$SWAP_FREE" \
--data-urlencode "memsize=$MEM_SIZE" --data-urlencode "memfree=$MEM_FREE" \
- --data-urlencode "runmode=$SLX_RUNMODE_MODULE" --data-urlencode "cpuload=$CPU_LOAD" \
- --data-urlencode "cputemp=$CPU_TEMP" \
+ --data-urlencode "runmode=$SLX_RUNMODE_MODULE" "$@" \
"$SLX_REMOTE_LOG" > /dev/null 2>&1
# Warn user if tmp or swap usage is high; system might crash soon