blob: ebed025be84807a7530399c405ea67f540ce1095 (
plain)
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
34
35
36
37
38
39
|
#!/bin/sh
# for UPS monitoring with NUT, and AMD GPU power querying through lm_sensors (09-26-2026)
#
DATA_CMD="upsc ups@localhost"
# on debian and freebsd, ups.realpower is not available.
# calculate load in watts with load percent and max output instead.
#MAX_OUTPUT=$($DATA_CMD | grep ups.realpower.nominal: | awk '{print $2}')
#LOAD_VALUE=$($DATA_CMD | grep ups.load: | awk '{print $2}')
#LOAD_PERCENT=$(echo "scale=2; $LOAD_VALUE/100" | bc)
#POWER=$(echo "scale=0; $LOAD_PERCENT*$MAX_OUTPUT" | bc)
UPS_POWER="$($DATA_CMD | grep ups.realpower: | awk '{print $2}')W"
# "round" to integer. just removes decimal and whatevers after.
#POWER="${POWER%.*} W"
UPS_CHARGE="$($DATA_CMD | grep battery.charge: | awk '{print $2}')%"
GPU_POWER="$(sensors | grep "PPT" | awk '{print $2}' | sed 's/\.00//g')W"
if [ "$UPS_CHARGE" = "100%" ]; then
echo "UPS: $UPS_POWER GPU: $GPU_POWER"
else
echo "UPS: $UPS_CHARGE $UPS_POWER GPU: $GPU_POWER"
fi
# for battery monitoring everywhere else
#
# if power_now is not present, calculate it:
#VOLTAGE=$(cat /sys/class/power_supply/BAT*/voltage_now)
#CURRENT=$(cat /sys/class/power_supply/BAT*/current_now)
#POWER=$(echo "scale=2; $VOLTAGE*$CURRENT/1000000000000" | bc)
# if it is present, just divide it to watts (from micro watts on thinkpads, perhaps something else on other platforms)
#POWER=$(cat /sys/class/power_supply/BAT*/power_now)
#POWER="$(echo "scale=2; $POWER/1000000" | bc)W"
#CHARGE="$(cat /sys/class/power_supply/BAT*/capacity)%"
#echo "$CHARGE $POWER"
|