Monitor your ups using mrtg

For a long time i wanted to monitor my UPS a APC SmartUPS 700VA using mrtg.
The main problem is that the ups doesn’t support snmp.

APCUPSD is a great program to monitor your ups (battery level, Load, etc) and shutdown your pc when the battey level is below a value. But it doesn’t provide snmp info.

Lucky for us, APCUPSD provides a tool (apcaccess ) to show the values that it can read from your ups. With the help of apcaccess, grep, awk and a shell script you can use it to feed the values to mrtg.

Step 1
Create the following script
[code]#!/bin/sh
#

a=`/sbin/apcaccess | grep LOADPCT | awk {‘print $3’}`

echo $a
echo 0
echo 0
echo ups[/code]
Name it apcups.sh and put it on /usr/local/bin

Step 2
Create the following mrtg configuration file
[code]
WorkDir: /var/www/html/mrtg-ups

Target[ups]: `/usr/local/bin/apcups.sh`
MaxBytes[ups]: 100
Title[ups]: Ups Load
PageTop[ups]: UPS Load
Options[ups]: growright, gauge, nopercent
YLegend[ups]: percent
Legend1[ups]: UPS Load
Legend2[ups]:
LegendO[ups]:
LegendI[ups]: UPS Load
ShortLegend[ups]: %[/code]

And make sure that workdir exists.

Then put a cronjob to run that script every 5 minutes
[code]
*/5 * * * * root /usr/bin/mrtg path_to_your_mrtg-ups.cfg_file
[/code]

If you want to speed the thinks up, run it 2 times then have look on the Workdir to see that the files have been generated succefull.

I use it to monitor the UPS load only, of course it can be modified to monitor also battery level, line voltage etc.

Nice ? 🙂 🙂

2 thoughts on “Monitor your ups using mrtg”

Comments are closed.