Atom Feed
Comments Atom Feed


Similar Articles

14/05/2015 22:35
PHP APC on Cacti via SNMP
31/10/2009 16:02
LM Sensors stats on Cacti (via SNMP)
12/03/2016 15:33
PHP Zend opcache on Cacti via SNMP
22/11/2009 16:49
Postfix stats on Cacti (via SNMP)
14/11/2009 13:46
Apache stats on Cacti (via SNMP)
08/01/2015 22:58
Nginx on Cacti via SNMP

Recent Articles

23/04/2017 14:21
Raspberry Pi SD Card Test
07/04/2017 10:54
DNS Firewall (blackhole malicious, like Pi-hole) with bind9
28/03/2017 13:07
Kubernetes to learn Part 4
23/03/2017 16:09
Kubernetes to learn Part 3
21/03/2017 15:18
Kubernetes to learn Part 2

Glen Pitt-Pladdy :: Blog

apcupsd stats on Cacti (via SNMP)

Following on from the basics of SNMP I did previously, this article now adds another set of SNMP extension scripts, config, and Cacti templates to monitor APC UPS' via apcupsd.

apcupsd Config

apcupsd is one of the standard ways of monitoring APC UPS' and has a huge variety of devices and connectivity options. It can also serve the status information to other hosts which avoids needing a network management card.

To get the status for Cacti, I use the network service (NIS as it is known in the config), so you need to ensure that this is enabled and available on the local interface. Since I have already got SNMP v3 configured with encryption on the server, I chose to use this to transmit the data rather than allow apcupsd to serve the data to the cacti monitoring server. The script I provide could easily be modified to allow remote monitoring without SNMP by passing the hostname argument through to apcaccess and adding labels to the parameters.

If your config is correct then you should be able to get a list of parameters from apcupsd by running:

$ /sbin/apcaccess status localhost

Getting apcupsd satus over SNMP

I have created a simple Perl wrapper script for apcaccess to get it into SNMP.

Download:  Perl script and Cacti Templates for apcupsd are on GitHub

I place script apcupsd-stats (make it executable first: chmod +x apcupsd-stats) in /etc/snmp

In /etc/snmp/snmpd.conf add the following line:

extend apcupsd /etc/snmp/apcupsd-stats

Once you have added all this in you can test apcupsd-stats by running it from the command line, and via SNMP by appending the appropriate SNMP OID to the "snmpwalk" commands shown previously.

Cacti Templates

I have generated some basic Cacti Templates for apcupsd. Since different model UPS' give different information, not all the graphs may be appropriate on your UPS. On my one the Output Voltage always gives 230V. the Internal Temperature always 29.2°C, and although the Line Frequency does vary, it does this in steps of 1Hz which is way to course of be of interest.

Simply import the template cacti_host_template_apcupsd.xml, and add the graphs you want to the appropriate device graphs in Cacti. It should just work if your SNMP is working correctly for that device (ensure other SNMP parameters are working for that device).

Graph Screen Shots

apcupsd over SNMP on Cacti : Battery Charge

apcupsd over SNMP on Cacti : Battery Voltage

apcupsd over SNMP on Cacti : Internal Temperature

apcupsd over SNMP on Cacti : Line Frequency

apcupsd over SNMP on Cacti : Line Voltage

apcupsd over SNMP on Cacti : Line Voltage, no Output

apcupsd over SNMP on Cacti : Load Percent

apcupsd over SNMP on Cacti : Load Power

apcupsd over SNMP on Cacti : Status

apcupsd over SNMP on Cacti : Time Left


Different versions of Cacti:

One person had pointed out that there has been some problems on some versions of Cacti with importing the templates. The template was generated with version 0.8.7b (from Debain Lenny).

The problem manifests it's self as "Cacti version does not exist" error, and appears to be cured by adding in this version, although in my version the file is actually global_arrays.php

The relevant array from my global_arrays.php / config_array.php:

$hash_version_codes = array(
    "0.8.4"  => "0000",
    "0.8.5"  => "0001",
    "0.8.5a" => "0002",
    "0.8.6"  => "0003",
    "0.8.6a" => "0004",
    "0.8.6b" => "0005",
    "0.8.6c" => "0006",
    "0.8.6d" => "0007",
    "0.8.6e" => "0008",
    "0.8.6f" => "0009",
    "0.8.6g" => "0010",
    "0.8.6h" => "0011",
    "0.8.6i" => "0012",
    "0.8.6j" => "0013",
    "0.8.7"  => "0014",
    "0.8.7a" => "0015",
    "0.8.7b" => "0016",
    "0.8.7c" => "0017",
    "0.8.7d" => "0018",
    "0.8.7e" => "0019",
    "0.8.7f" => "0020",
    "0.8.7g" => "0021"



Chandrakanta Sahoo Image  17/01/2011 11:51 :: Chandrakanta Sahoo

I have installed Cacti Version 0.8.7e on my CENTOS-5.5 Server & getting the graphs of some network devices. I want to add my APC Switched Rack PDU in cacti to view the performance graph. My APC Switched Rack PDU is connected to my network switch not directly connected to my cacti server. I have installed apcupsd on my cacti server. Then I have created a file in /etc/snmp/ & given the execute permission. Then I issue the below command & get the below error:

[andola-sys1@nagios ~]$ /sbin/apcaccess status
Error contacting apcupsd @ Connection refused
[andola-sys1@nagios ~]$ /sbin/apcaccess status
Error contacting apcupsd @ Connection refused

SO please help me to do the same

Dave Image  22/07/2012 01:34 :: Dave

Hi, I've done all as described but the graphs are not showing. What do you mean by appending the appropriate SNMP OID to the "snmpwalk"? Is there anything else what I should do what is not described in the article? Thanks. Regards, Dave

Glen Pitt-Pladdy Image  22/07/2012 09:07 :: Glen Pitt-Pladdy

By default snmpwalk will not walk the extended OID which has these stats on. What is needed is to add an OID to view as much (or as little) of the stats as you want. These are in the data templates. To view all extended out put you could use the OID of: NET-SNMP-EXTEND-MIB::nsExtendOutLine

Generally the best diagnosis is to start by running snmpwalk from the Cacti server and that will tell you if you are getting valid stats out of snmpd. From there you can diagnose whichever side is the problem.

Dave Image  22/07/2012 20:20 :: Dave

Thanks Glen! I've managed to walk it from command line and it returns correct strings from my ups. The only problem is I don't know how to add the query to cacti :) I tried in different ways but it doesn't generate any graphs from templates (no image). Where should I add it and how? Dave

Glen Pitt-Pladdy Image  22/07/2012 20:26 :: Glen Pitt-Pladdy

We can bet on the problem being on the Cacti side then. First thing is to check that SNMP is correctly configured for the host in Cacti - you should see "SNMP information" below the host name in the Devices section with the ID of the OS and a load of other info retrieved via snmp. If not then it's likely the config problem is right there on that page.

Once the template xml is imported you should see various apcupsd graphs that you can add. If they fail to update then it's worth checking the logs which may have an explanation. It generally takes 2-3 of polls before the graphs have stuff on them.

Dave Image  22/07/2012 23:03 :: Dave

My fault, I didn't know I need to configure SNMP under cacti settings. Thanks for the your tips. Now it works like a charm. Great job. Thanks Glen.

Glen Pitt-Pladdy Image  23/07/2012 05:37 :: Glen Pitt-Pladdy

Good to know you got it sorted!

Frank Image  14/08/2014 06:06 :: Frank

Had working the script on CentOS 5.6 long time - now changed to CentOS 6.5 and get:

# sh /etc/snmp/apcupsd-stats
/etc/snmp/apcupsd-stats: line 25: or: command not found
/etc/snmp/apcupsd-stats: line 26: syntax error near unexpected token `$line'
/etc/snmp/apcupsd-stats: line 26: `while ( defined ( $line = <AC> ) ) {'

It's a default installation of Perl - are there any CPAN modules required?

best regards

Glen Pitt-Pladdy Image  14/08/2014 11:47 :: Glen Pitt-Pladdy

The script should be executable its self and so relies on the #! at the start. The way you are launching it (with "sh") what is happening is that it is trying to run Perl script in shell.... and that's not going to work.

Frank Image  14/08/2014 13:38 :: Frank

okay, thanks - it's working but I hade to change some text ID for getting valid values for my APC RT 2000 XL:

print "$field{LINEV}\n";
print "$field{OUTPUTV}\n";
print "$field{LOTRANS}\n";
print "$field{HITRANS}\n";
print "$field{BATTV}\n";
print "$field{NOMBATTV}\n";
print "$field{BCHARGE}\n";
print "$field{TIMELEFT}\n";
print "$field{ITEMP}\n";
print "$field{LOADPCT}\n";
# print "0\n";
print ''.(10*$field{'LOADPCT'})."\n";
print "1000\n";
print "$field{LINEFREQ}\n";
if ( $field{'STATUS'} eq 'ONLINE' ) {
        print "100\n0\n";
} else {
        print "0\n100\n";

Now everything looks fine. Thanks.
best regards

Are you human? (reduces spam)
Note: Identity details will be stored in a cookie. Posts may not appear immediately