September 4, 2008

Power monitoring and logging with Apcupsd and Cacti

Author: Colin Beckingham

For some time I have been using the American Power Conversion (APC) uninterruptible power supply (UPS) daemon Apcupsd to interface my desktop computer with my APC Back-UPS ES 550. Available for Linux, Windows, Mac OS X, and Solaris 10, Apcupsd reliably warns me when the power goes out and gives me time to get my box properly shut down before data is lost, or does so automatically if I am not there to supervise.

The Back-UPS ES 550 is a small battery-based backup power supply that communicates with the desktop via a USB cable. Installing Apcupsd was straightforward. I downloaded the source files for the latest version 3.14.4 and a PDF manual, and installed the daemon and tools with the commands:

./configure --enable-cgi --enable-usb
make install

Note that the --enable-usb option for configure defaults to false and specifically needs to be enabled if the interface is USB. I added the line /sbin/apcupsd start to my /etc/init.d/boot.local file to ensure that the Apcupsd daemon would start with each reboot of the computer.

Apcupsd needed minimal configuring for my UPS. To allow the daemon to see and query the box, I edited the configuration file /etc/apcupsd/apcupsd.conf to indicate

DEVICE (blank)

After simulating one power outage by unplugging the UPS from the wall socket, I tested the install with the tool apcaccess, which produced the following output:

APC : 001,037,0951
DATE : Wed Aug 13 16:35:20 EDT 2008
HOSTNAME : xxxxxxx
RELEASE : 3.14.4
VERSION : 3.14.4 (18 May 2008) suse
UPSNAME : xxxxxxx
MODEL : Back-UPS ES 550
UPSMODE : Stand Alone
STARTTIME: Wed Aug 13 12:37:56 EDT 2008
LINEV : 112.0 Volts
LOADPCT : 25.0 Percent Load Capacity
BCHARGE : 100.0 Percent
TIMELEFT : 20.8 Minutes
MBATTCHG : 5 Percent
MINTIMEL : 3 Minutes
MAXTIME : 0 Seconds
SENSE : High
LOTRANS : 088.0 Volts
HITRANS : 139.0 Volts
BATTV : 13.4 Volts
LASTXFER : Low line voltage
XONBATT : Wed Aug 13 12:49:56 EDT 2008
TONBATT : 0 seconds
CUMONBATT: 17 seconds
XOFFBATT : Wed Aug 13 12:50:13 EDT 2008
STATFLAG : 0x07000008 Status Flag
MANDATE : 2006-11-14
SERIALNO : xxxxxxxxx
BATTDATE : 2000-00-00
NOMINV : 120 Volts
NOMBATTV : 12.0 Volts
END APC : Wed Aug 13 16:35:24 EDT 2008

You can configure many of these observations by editing the config file
/etc/apcupsd/apcupsd.conf. The comprehensive manual provides the details. At this point the UPS can communicate with the operating system and say when the box is in danger of losing power and should be shut down, and if necessary also trigger powering up again.

Apcupsd has its own CGI graphical user interface included in the download which, through a browser, lets you see the current state of the backup system, giving you an idea of remaining battery capacity. However, a more interesting logging facility is available.

The Cacti logging interface

Cacti is a graphical front end to the logging functions of RRDtool, which stores the data in a format that can be readily graphed. With the right interface between Apcupsd, RRDtool, and Cacti, we not only have information on the current state of the box and line, but also historical data.

Interface files for connecting Apcupsd to Cacti are available on the Cacti forums. The package includes a couple of scripts and two XML template files that need to be imported into Cacti, and some instructions about modifying cron. I found that each of the scripts had a line at the top of the file related to attachment content that had to be removed before they would run. However, once I installed them and let things run for half an hour or so, I was able to produce some data charts.

Since Apcupsd produces readable reports each time it scans the state of the box and the power supply, you can take advantage of that and produce a useful history log of the parameters the UPS is aware of, such as changes in the state of the power line and the state of battery capacity over time, and you can display the information in Cacti. Here is a sample:

The top line is the line voltage. The next line down is the battery capacity in percent. At about the 1:00 p.m. mark I created a test power outage by unplugging the UPS from the wall. Line voltage went to zero, then came back up shortly afterward when I plugged the UPS back in. The green line shows how quickly the battery was able to return to full capacity.


There are a number of ways of getting your desktop to interface well with a UPS. Which works best for you may depend on whether there are prebuilt binaries available for your distribution. I found it easiest to compile all the tools from source. I then had an effective and informative window into my UPS using the Apcupsd, RRDtool, and Cacti combination.


  • Tools & Utilities
  • Desktop Hardware
Click Here!