This is a read-only archive. Find the latest Linux articles, documentation, and answers at the new!

Feature: Tools & Utilities

Power monitoring and logging with Apcupsd and Cacti

By Colin Beckingham on September 04, 2008 (7:00:00 PM)

Share    Print    Comments   

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 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


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 CABLE : USB Cable MODEL : Back-UPS ES 550 UPSMODE : Stand Alone STARTTIME: Wed Aug 13 12:37:56 EDT 2008 STATUS : ONLINE 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 ALARMDEL : Always BATTV : 13.4 Volts LASTXFER : Low line voltage NUMXFERS : 1 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 FIRMWARE : 840.B2.D USB FW:B2 APCMODEL : Back-UPS ES 550 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.

Colin Beckingham is a freelance programmer and writer in Eastern Ontario. He is currently working on a project that logs and charts the operation of a biomass burner using open source resources.

Share    Print    Comments   


on Power monitoring and logging with Apcupsd and Cacti

Note: Comments are owned by the poster. We are not responsible for their content.

Power monitoring and logging with Apcupsd and Cacti

Posted by: Anonymous [ip:] on September 04, 2008 09:48 PM
Mr. Beckingham is perhaps generous when he says the installation of apcupsd is straightforward; my experience, wanting to be thorough and make sure I fully understood what I was doing, was that I had to skim through most of the nearly-daunting manual just to come to the conclusion that, yes, for my simple needs installation was about as simple as Mr. Beckingham describes.

I say the manual is "nearly-daunting" not because it's incomprehensible but only because it is, as Mr. Beckingham also says, comprehensive. *Really* comprehensive. Apcupsd ain't your daddy's PowerChute; it's complicated and sophisticated, with, for example, the ability to control multiple machines over a network via one master machine that the UPS communicates with. The very good manual reflects this complexity and more. I'd recommend portions of this manual as a generic USB troubleshooting guide too.

But it doesn't make it simple to realize that using apcupsd for simple scenarios is really reasonably simple. And it's not as simple as you might hope because it has to modify shutdown scripts for various different distros, and a UPS-initiated shutdown is surprisingly involved, and if you're like me you feel compelled to check up on what it did and make sure you understand it all and that it's really going to work. It's not bad, but it's a bit more involved than "./configure ; make ; make install".


Power monitoring and logging with Apcupsd and Cacti

Posted by: Anonymous [ip:] on September 05, 2008 06:48 PM
The true URL to the Cacti site is:


This story has been archived. Comments can no longer be posted.

Tableless layout Validate XHTML 1.0 Strict Validate CSS Powered by Xaraya