Graphing power consumption with xymon

Abstract

Electricity becomes more and more expensive. If you run a data center you care about power consumption, because the less you use the more competitve you can act on the market. We run a Raritan Dominion PX Power switch at work and I decided it was about time to let it tell me how much power our servers consume.

One of the machines I work with is a Raritan Dominion PX Power switch. I mostly use it to remotely power cycle faulted servers, but there's more to it than meets the eye. The switch can also measure some special parameters e.g. power consumption in WATT.

That's something that caught my attention right away, because it has become vital to keep an eye on power consumption in data centers - it makes up for most of the costs today.

I wanted to have some graphs and counters and started by adding a new entry at the central xymonserver in /etc/xymon/hosts.cfg like this:

...
#group powercontrol
group powercontrol
page POWERCONTROL powercontrol
1.2.3.4 powerswitch1 # testip conn NAME:powerswitch1 TRENDS:* \
    DESCR:raritan_powerswitch1
....

Then I created a few external shell scripts on the central xymon server. They are located xymons client section. Here's an example I stored in /usr/lib/xymon/client/ext/powerswitch1-outlet-1.sh:

#!/bin/sh
COLUMN=outlet1
COLOR=green
MACHINE=powerswitch1
$BB $BBDISP "status $MACHINE.$COLUMN $COLOR `date`
`sudo /usr/bin/snmpwalk -v2c -c power 1.2.3.4. -m PDU-MIB outletActivePower | \
     head -1 | awk 'BEGIN  { FS = " " } ; { print $3 " " $4 }' | \
     sed 's/Gauge32:/watts :/'`
"
exit 0

I ended up creating 8 scripts, since our powerswitch has 8 so called pdus ( power outlets ) I wanted to poll for information. The second script, /usr/lib/xymon/client/ext/powerswitch1-outlet-2.sh , looked like this:

#!/bin/sh
COLUMN=outlet2
COLOR=green
MACHINE=powerswitch1
$BB $BBDISP "status $MACHINE.$COLUMN $COLOR `date`
`sudo /usr/bin/snmpwalk -v2c -c power 1.2.3.4. -m PDU-MIB outletActivePower | \
     awk 'BEGIN { FS = " " } ; { print $3 " " $4 }' | sed 's/Gauge32:/watts :/' | \
     sed -n 2p`
"
exit 0

I copied the script over and changed COLUMN and the sed options as required per pdu:

...
COLUMN=outlet3
... sed -n 3p`
...

Then I created a task cfg to start each shell script job at server client launch.

% cd /usr/lib/xymon/client/etc/tasks.d

The task cfg (/usr/lib/xymon/client/etc/tasks.d/powerswitch1-outlet-1.cfg) looked liks this:

[outlet1]
ENVFILE /etc/xymon/xymonclient.cfg
CMD $XYMONCLIENTHOME/ext/powerswitch1-outlet-1.sh
LOGFILE /var/log/xymon/powerswitch1-outlet-1.log
INTERVAL 1m

I then copied the file to /usr/lib/xymon/client/etc/tasks.d/powerswitch1-outlet-2.cfg and incremented all numbers and script references by 1. I iterated this procedure until I had all pdus under control.

Note

Don't forget to give sudo privileges like this in /etc/sudoers:

...
xymon ALL=(root) NOPASSWD: /usr/bin/snmpwalk
...

All this done I was ready to tell xymon it should create graphs. In /etc/xymon/xymonserver.cfg I added:

...
TEST2RRD="...,outlet1=ncv,outlet2=ncv,outlet3=ncv,..."
GRAPHS="...,outlet1,outlet2,outlet3,..."
NCV_outlet1="*:GAUGE"
NCV_outlet2="*:GAUGE"
NCV_outlet3="*:GAUGE"
...

And then in /etc/xymon/graphs.cfg:

...
     [outlet1]
     TITLE outlet1
     YAXIS #
     DEF:watts=outlet1.rrd:watts:AVERAGE
     LINE2:watts#00CCCC:outlet1
     GPRINT:watts:LAST:watts \: %5.1lf%s (cur)
     GPRINT:watts:MAX: \: %5.1lf%s (max)
     GPRINT:watts:MIN: \: %5.1lf%s (min)
     GPRINT:watts:AVERAGE: \: %5.1lf%s (avg)\n

     [outlet2]
     TITLE outlet2
     YAXIS #
     DEF:watts=outlet2.rrd:watts:AVERAGE
     LINE2:watts#00CCCC:outlet2
     GPRINT:watts:LAST:watts \: %5.1lf%s (cur)
     GPRINT:watts:MAX: \: %5.1lf%s (max)
     GPRINT:watts:MIN: \: %5.1lf%s (min)
     GPRINT:watts:AVERAGE: \: %5.1lf%s (avg)\n
...

Then I restarted the xymon server and ever since then I have nice graphs like this one:

Robert Schetterer, 17. January 2013