Theserve Blog

web hosting and virtual server blogHow to monitor the current load of an APC 7900

Posted On: 21st December 2011 under linux

Power is now one of the biggest expenses inside the data centre and keeping an eye on your usage is always a good idea.

The average rack will have 8 to 16 amps of power and its very easy to consume all of this power. In fact its quite hard to fill a rack to the brim with less than 20 amps and quite often going too close to your power limit can end in disaster if you hit the circuit breakers limits!

Understanding how much power you are using in your rack can help you plan and provision your resources in an efficient manner. Most servers are connected to managed PDU's such as the APC AP7900 series. We have several of these in each of our racks and in order to make sure we have some room before we hit the breakers its essential for us to monitor our total usage accross each of the bars.

Fortunately the bars themselves have a load monitor built in which you can view by logging in to the admin interface. However, its not efficient to manually login to several different bars and tally up the total power consumption - thats were SNMP is our friend!

The APC's can be controlled in many ways using SNMP, however in this article all we are interested in is fetching the current load of the bar.

We assume you have configured your APC to enable read SNMP access (It's incredibly simple to do from the admin pages of the APC).

We are going to use PHP and snmpwalk to fetch the data from the power bars and total up the usage but you could use any programming language to collect this information such as Perl or C.

Snmpwalk will fetch the data you need from the power bar you just need an IP or hostname of the device, a community name and an SNMP MIB to query.

This is the command we use to fetch the status from one bar:

[root@theserve ~]# snmpwalk -Os -c public -v 1 192.168.0.10 enterprises.318.1.1.12.2.3.1.1.2.1

Where public is the community name, 192.168.0.10 is the IP of the APC and the most important part enterprises.318.1.1.12.2.3.1.1.2.1 is the MIB for the load usage. Below is the typical response we will see.

enterprises.318.1.1.12.2.3.1.1.2.1 = Gauge32: 24

We can see here looking at the result we are using 2.4Amps on this bar. The units are in 10ths of an Amp so the usage can be calculated by dividing the figure by 10.

So finally putting this all together using a php script we get the following:

<?php
date_default_timezone_set('GMT');

$servers = array("192.168.0.10","192.168.0.11","192.168.0.12","192.168.0.13","192.168.0.14");

$total          = 0;

for($i = 0; $i < count($servers); $i++)
{
        $output = "";
        $command = "snmpwalk -Os -c public -v 1 " . $servers[$i] . " enterprises.318.1.1.12.2.3.1.1.2.1";
        exec($command, &$output, &$return_var);
        $values = explode(": ", $output[0]);
        $total += $values[1]/10;
}

if($total > 15)
{
        mail("mail@theserve.com", "APC LOAD EXCEEDED 15A", "APC LOAD EXCEEDED 15A", "From: mail@theserve.com");
}
?>

This script is then executed from cron every minute to keep tabs on our power usage. If the total exceeds 15Amps it will send an email to us alerting us that we are close to our threshhold. In our production environment we actually store the results of this script and use it to compile a chart of power usage.