APC UPS graphs

For the past 2 weeks I’ve been working on a script that uses the free software project apcupsd to regularly poll an APC UPS, collect statistics (Line Voltage, Battery Load, Time Remaining) and then create graphs from this data using gnuplot.

If you have a typical Linux system with all the standard tools (bash, grep, awk, sed, tac) and gnuplot installed with libpng support (you probably do) then it should work for you. First, make sure you are running apcupsd and that the “apcaccess” program works for communicating with your UPS. If it does, all you need to do is tweak a few options in the script and setup a cron job to run it at whatever interval of time you’d like your graphs to cover. I currently keep 4032 entries for each data point, run at 5 minute cron intervals which comes out to 1 week’s worth of data.

The graphs are PNG images, intended to be displayed with a web server, but if you just want the images, comment out the HTML portions of the script. I have tried to make it easy to understand and modify.

To see a live example of my UPS data, go to airwaterunix.org/ups.

And here’s the script: http://airwaterunix.org/makegraphs.sh