summaryrefslogtreecommitdiffstats
path: root/core/modules/hardware-stats
diff options
context:
space:
mode:
authorSimon Rettberg2020-04-24 20:13:51 +0200
committerSimon Rettberg2020-04-24 20:13:51 +0200
commit51340cff7dee8bda3c5ac4a92195ba6bd432f898 (patch)
tree5a98c6bc612b2f6542e586dc9604682f948db553 /core/modules/hardware-stats
parent[kiosk-chromium] Fix syntax error (diff)
downloadmltk-51340cff7dee8bda3c5ac4a92195ba6bd432f898.tar.gz
mltk-51340cff7dee8bda3c5ac4a92195ba6bd432f898.tar.xz
mltk-51340cff7dee8bda3c5ac4a92195ba6bd432f898.zip
[hardware-stats] Tweak hooks for immediate usage updates; add %CPU stat
The hooks that immediately call the usage update script have been modified to only fire for :0 X11 sessions, and also trigger for Xreset, which usually means a session ended. Also added a %CPU stat that gets reported every 5 minutes.
Diffstat (limited to 'core/modules/hardware-stats')
-rw-r--r--core/modules/hardware-stats/data/etc/X11/Xreset.d/update-usage-stats4
-rw-r--r--core/modules/hardware-stats/data/opt/openslx/pam/hooks/session-open.d/usage_stats6
-rwxr-xr-xcore/modules/hardware-stats/data/opt/openslx/scripts/cron-system_usage_update36
-rwxr-xr-xcore/modules/hardware-stats/data/opt/openslx/system-check/hooks.d/50-hardware-report4
4 files changed, 40 insertions, 10 deletions
diff --git a/core/modules/hardware-stats/data/etc/X11/Xreset.d/update-usage-stats b/core/modules/hardware-stats/data/etc/X11/Xreset.d/update-usage-stats
new file mode 100644
index 00000000..03ab852e
--- /dev/null
+++ b/core/modules/hardware-stats/data/etc/X11/Xreset.d/update-usage-stats
@@ -0,0 +1,4 @@
+#!/bin/ash - sourced
+
+[ "$DISPLAY" = ":0" ] && /opt/openslx/scripts/cron-system_usage_update &
+
diff --git a/core/modules/hardware-stats/data/opt/openslx/pam/hooks/session-open.d/usage_stats b/core/modules/hardware-stats/data/opt/openslx/pam/hooks/session-open.d/usage_stats
index e2154aa7..0c287f04 100644
--- a/core/modules/hardware-stats/data/opt/openslx/pam/hooks/session-open.d/usage_stats
+++ b/core/modules/hardware-stats/data/opt/openslx/pam/hooks/session-open.d/usage_stats
@@ -1,9 +1,7 @@
#!/bin/ash - sourced
-if [ "x$PAM_SERVICE" != "xsu" -a "x$PAM_SERVICE" != "xsudo" ]; then
- sleep 3
+if [ "$DISPLAY" = ":0" ] || [ "$PAM_TTY" = ":0" ]; then
+ sleep 4
/opt/openslx/scripts/cron-system_usage_update
fi &
-true
-
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 0ddb6159..6e0b7a9e 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
@@ -1,5 +1,9 @@
#!/bin/ash
+touch /run/openslx || exit 1
+full=false
+[ "$1" = "--full" ] && full=true
+
[ -r "/etc/system-uuid" ] || exit 0
. /opt/openslx/config
@@ -16,14 +20,16 @@ Name=
LEGEND=
loginctl --help 2>&1 | grep -q -- '--no-legend' && LEGEND="--no-legend"
for SESSION in $(loginctl $LEGEND | awk '{print $1}'); do
- unset Display Remote State
- eval $(loginctl -p Display -p Remote -p State -p Class -p Name show-session "$SESSION")
+ unset Display Remote State Class
+ eval "$(loginctl -p Display -p Remote -p State -p Class -p Name show-session "$SESSION")"
if [ "$Display" = ":0" ] && [ "$Remote" = "no" ] && [ "$State" = "active" -o "$State" = "online" ] && [ "$Class" = "user" ]; then
USED=1 # We only consider sessions on the primary display, which should always be the case
- break
+ break # keeps $Name set!
fi
+ unset Name
done
+
# Also report usage of /tmp and swap
TMP="$( slx-tools fs_path_space /tmp )"
TMP_FREE="${TMP% *}"
@@ -40,12 +46,34 @@ if [ -n "$SLX_EXAM" ]; then
# to know about it, more than other runmodes actually
SLX_RUNMODE_MODULE="exams"
fi
+# CPU temp and load
+CPU_LOAD=
+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
+ 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) }' )"
+ fi
+ else
+ write=true
+ fi
+ if $write; then
+ echo "$current" > "/run/openslx/usage.state"
+ fi
+fi
curl --retry 3 --retry-connrefused -m 6 -s --data-urlencode "type=~runstate" --data-urlencode "uuid=$UUID" --data-urlencode "used=$USED" \
--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" "$SLX_REMOTE_LOG" > /dev/null 2>&1
+ --data-urlencode "runmode=$SLX_RUNMODE_MODULE" --data-urlencode "cpuload=$CPU_LOAD" \
+ "$SLX_REMOTE_LOG" > /dev/null 2>&1
# Warn user if tmp or swap usage is high; system might crash soon
diff --git a/core/modules/hardware-stats/data/opt/openslx/system-check/hooks.d/50-hardware-report b/core/modules/hardware-stats/data/opt/openslx/system-check/hooks.d/50-hardware-report
index a17e9ead..31b0b26f 100755
--- a/core/modules/hardware-stats/data/opt/openslx/system-check/hooks.d/50-hardware-report
+++ b/core/modules/hardware-stats/data/opt/openslx/system-check/hooks.d/50-hardware-report
@@ -70,13 +70,13 @@ report_hardware_info() {
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/openslx/sbin:/opt/openslx/bin
- ${START}-59/5 * * * * root sleep ${DELAY}; /opt/openslx/scripts/cron-system_usage_update
+ ${START}-59/5 * * * * root sleep ${DELAY}; /opt/openslx/scripts/cron-system_usage_update --full
EOF
# TODO remove this hack one day: Sometimes, aufs doesn't update the mtime of dirs
# when creating files, so cron would not rescan the cron directory.
touch "/etc/cron.d"
# Trigger right now so resource usage gets updated
- /opt/openslx/scripts/cron-system_usage_update
+ /opt/openslx/scripts/cron-system_usage_update --full
return 0
}