APC power rails – Power data

A few weeks ago i was given an interesting task to play with: Get the power data from all of our APC power rails and graph it. I thought: Ok, this should be a fun little project!

And it was fun. In brief – the rails have SNMP, and a OID that gives you the total power, if its a 32 amp rail – give it to you per bank + an overall. So i got it all graphed in Cacti and made a pretty overall graph which updates every minute – nice to know how much power we draw!

Then last week another thing came up – we need to move servers from one datacenter to another, but need to know how much power we would end up using. I explored the option of a new graph, but we just needed a one of value and maybe 2 more times – the cacti path takes about 15 minutes per rail. So i scripted the following – its messy, but did what i need. Please feel free to fix it up if you want – i would be happy to repost if you do

<?php
$finalpower = 0;
$ipblock = "192.168.xx.";
$oid32 = ".1.3.6.1.4.1.318.1.1.12.2.3.1.1.2.3";
$oid16 = ".1.3.6.1.4.1.318.1.1.12.2.3.1.1.2.1";
$command = "snmpwalk -v2c -c<YOUR SNMP STRING>";

$rail16 = array(10,11,12,13,14,15,16,17,21,22,25,26,27,28,29,30,31,32,33,34,39,40,60,61,143,144,35,36,37,38,41,42,58,59);
$m32 = array (50,51,52,53,54,55,56,57);

foreach($rail16 as $rail){
$runme = ''.$command.' '.$ipblock.''.$rail.' '.$oid16.'';
$crap = exec($runme);
$pwr = str_replace("SNMPv2-SMI::enterprises.318.1.1.12.2.3.1.1.2.1 = Gauge32: ","", $crap) /10;
$finalpower = $finalpower + $pwr;
}

foreach($m32 as $rail){
$runme = ''.$command.' '.$ipblock.''.$rail.' '.$oid32.'';
$crap = exec($runme);
$pwr = str_replace("SNMPv2-SMI::enterprises.318.1.1.12.2.3.1.1.2.3 = Gauge32: ","", $crap) /10;
$finalpower = $finalpower + $pwr;
}

$num16 = count($rail16);
$num32 = count($m32);
$railtotal = $num16 + $num32;
echo "number of rails: $railtotal || total power: $finalpower";
?>

So basically, you set a IP range at the top, then the array holds the last octet of each rail, it loops through it SNMP walking the data (this could be changed to PHP SNMP). We divide by 10 as the rails output data like: 37 to SNMP, but the real world value is 3.7 – hence divide by 10.

This script is quick and dirty, but with a little work, could clean up nice 🙂

Leave a Reply

Your email address will not be published.

Blue Captcha Image
Refresh

*

RSS
Pinterest
fb-share-icon
LinkedIn
LinkedIn
Share