Skip to content

Instantly share code, notes, and snippets.

@jelimoore
Created March 11, 2020 15:53
Show Gist options
  • Save jelimoore/1fd7277a9d9ca3d381a76c231da3c8df to your computer and use it in GitHub Desktop.
Save jelimoore/1fd7277a9d9ca3d381a76c231da3c8df to your computer and use it in GitHub Desktop.
#!/bin/bash
UPS_NAME="ups1"
GATHER_COMMAND="upsc ${UPS_NAME}"
(
M_CHARGE=$(${GATHER_COMMAND} | grep battery.charge | grep -v status | tr -d ' ' | cut -d ':' -f2)
M_INVOLT=$(${GATHER_COMMAND} | grep input.voltage | grep -v nominal | tr -d ' ' | cut -d ':' -f2)
M_OUTVOLT=$(${GATHER_COMMAND} | grep output.voltage | grep -v nominal | tr -d ' ' | cut -d ':' -f2)
M_TEMPERATURE=$(${GATHER_COMMAND} | grep ambient.temperature | grep -v high | tr -d ' ' | cut -d ':' -f2)
M_TEMPHIGH=$(${GATHER_COMMAND} | grep ambient.temperature.high | tr -d ' ' | cut -d ':' -f2)
M_BATTVOLT=$(${GATHER_COMMAND} | grep battery.voltage | tr -d ' ' | cut -d ':' -f2)
M_BATTRUN=$(($(${GATHER_COMMAND} | grep battery.runtime | grep -v low | cut -d' ' -f2)/60))
M_CURRENT=$(${GATHER_COMMAND} | grep output.current | grep -v nominal | cut -d':' -f2 | tr -d ' ')
M_LOAD=$(${GATHER_COMMAND} | grep ups.load | cut -d':' -f2 | tr -d ' ')
TIME=$(($(date +%s)*1000000000))
METRICS="charge_perc=${M_CHARGE},input_v=${M_INVOLT},output_v=${M_OUTVOLT},temp=${M_TEMPERATURE},temphigh=${M_TEMPHIGH},battvolt=${M_BATTVOLT},runtime=${M_BATTRUN},current=${M_CURRENT},load=${M_LOAD}"
echo ups,host=$(hostname -f),ups=${UPS_NAME} ${METRICS} ${TIME}
) 2>/dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment