46 lines
1.6 KiB
Bash
Executable File
46 lines
1.6 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
IFS=':'
|
|
|
|
while read -a line; do
|
|
# Clear out extra spaces
|
|
key=$(tr -d ' ' <<< ${line[0]})
|
|
val=${line[1]## }
|
|
val_num=$(grep -Eo '[0-9.]+' <<< $val)
|
|
|
|
case $key in
|
|
MODEL)
|
|
gmetric --name="ups_model" --value="$val" --type=string --group=ups --title="UPS model"
|
|
;;
|
|
LINEV)
|
|
gmetric --name="ups_line_voltage" --value="$val_num" --units="V" --type=float --group=ups --title="UPS line voltage"
|
|
;;
|
|
LOADPCT)
|
|
gmetric --name="ups_load_percent" --value="$val_num" --units="%" --type=float --group=ups --title="UPS load"
|
|
loadpct=$(tr -d '.' <<< $val_num) # Strip out decimals for bash's integer math (should now be in thousandths, for accuracy in case there is a decimal)
|
|
;;
|
|
BCHARGE)
|
|
gmetric --name="ups_battery_charge" --value="$val_num" --units="%" --type=float --group=ups --title="UPS battery charge"
|
|
;;
|
|
TIMELEFT)
|
|
gmetric --name="ups_time_left" --value="$val_num" --units="min" --type=float --group=ups --title="UPS time left"
|
|
;;
|
|
BATTV)
|
|
gmetric --name="ups_battery_voltage" --value="$val_num" --units="V" --type=float --group=ups --title="UPS battery voltage"
|
|
;;
|
|
TONBATT)
|
|
gmetric --name="ups_time_on_battery" --value="$val_num" --units="s" --type=uint32 --group=ups --title="UPS time on battery"
|
|
;;
|
|
BATTDATE)
|
|
gmetric --name="ups_battery_date" --value="$val" --type=string --group=ups --title="UPS battery date"
|
|
;;
|
|
NOMPOWER)
|
|
nompower=$val_num
|
|
;;
|
|
esac
|
|
done <<< $(/usr/sbin/apcaccess)
|
|
|
|
# Calculate load in watts
|
|
load_watts=$(( ($loadpct * $nompower) / 1000 ))
|
|
gmetric --name="ups_load" --value="$load_watts" --units="W" --type=float --group=ups --title="UPS load"
|