summaryrefslogtreecommitdiffstats
path: root/remote/modules/hardware-stats/data/opt/openslx/scripts/cron-system_usage_update
blob: ff5adc70984d485f60a922e52ec3927db4a70679 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/ash

[ -r "/run/system-uuid" ] || exit 0

. /opt/openslx/config
[ -z "$SLX_REMOTE_LOG" ] && exit 0

UUID=$(cat "/run/system-uuid")

[ -z "$UUID" ] && exit 1

USED=0
Name=

for SESSION in $(loginctl | awk '{print $1}'); do
	unset Display Remote State
	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
	fi
done

# Also report usage of /tmp and swap
TMP=$(df -P /tmp | grep -m1 ^/tmp)
TMP_SIZE=$(echo $TMP | awk '{print $2}')
TMP_FREE=$(echo $TMP | awk '{print $4}')
SWAP_FREE=$(grep -m1 ^SwapFree: /proc/meminfo | awk '{print $2}')

curl -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 "swapfree=$SWAP_FREE" "$SLX_REMOTE_LOG" > /dev/null 2>&1