Skip to content

Instantly share code, notes, and snippets.

@yangl1996
Last active October 1, 2017 13:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yangl1996/d45f36b85977b6df80a093808ee4fb7a to your computer and use it in GitHub Desktop.
Save yangl1996/d45f36b85977b6df80a093808ee4fb7a to your computer and use it in GitHub Desktop.
Get power reading from IPMI

Utils reading power meter using IPMI DCMI and recording value into a round-robin database (rrd).

  • readpower - reads IPMI power meter
  • pushover $title $message - pushes arbitrary message to my phone using Pushover
  • checkpower - reads power meter, writes the value into rrd and reports overage using Pushover
  • init-rrd.sh - creates a round-robin database at /opt/power.rrd

Export $PUSHOVER_TOKEN and $PUSHOVER_USER to set UID and API token.

Run checkpower every 1 sec by calling watch -n 1 -- checkpower.

To collect data and draw a graph, use rrdtool graph. An example is given here:

sudo rrdtool graph ./power-trace.png \
  -a PNG \
  -s -300s \
  -t 'Past 5 mins' \
  -w 600 -h 200 \
  DEF:watts=/opt/power.rrd:watts:AVERAGE \
  AREA:watts#00C000
#! /bin/bash
current_power=$(readpower)
sudo rrdtool update /opt/power.rrd N:$current_power
echo "Instantaneous Power Consumption: $current_power"
if [ $current_power -gt 2900 ]; then
pushover 'Power Overage' "Current power consumption is $current_power"
fi
sudo rrdtool create /opt/power.rrd --step 1s \
DS:watts:GAUGE:1m:0:5000 \
RRA:AVERAGE:0:3s:1h \
RRA:AVERAGE:0.2:10s:6h \
RRA:AVERAGE:0.5:30s:24h \
RRA:AVERAGE:0.5:5m:7d
#! /bin/bash
curl -s \
--form-string "token=$PUSHOVER_TOKEN" \
--form-string "user=$PUSHOVER_USER" \
--form-string "message=$2" \
--form-string "title=$1" \
http://api.pushover.net/1/messages.json | grep -q '"status":1'
if [ $? -ne 0 ]; then
>&2 echo 'pushover request failed'
exit 1
else
exit 0
fi
#! /bin/bash
sudo ipmitool dcmi power reading | sed -n '/Instantaneous power reading/s/^\s*Instantaneous power reading:\s*\([0-9][0-9]*\) Watts$/\1/p'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment