Search This Blog

Saturday, June 22, 2013

Monitoring APC UPS Batteries using Webmin on Ubuntu

I've been using an APC Back-UPS XS 1300 since initially building my media server approximately 2 years ago.  Until now, however, I've been blindly trusting it will do it's thing when I have a power outage/surge/brown-out.  I have come across a method to monitor the battery pack using my favorite monitoring and admin tool, Webmin.  Here goes:
  1. Install apcupsd and the cgi tools to enable web monitoring
    1. sudo apt-get install apcupsd apcupsd-cgi
  2. Edit the config file:
    1. gksudo gedit /etc/apcupsd/apcupsd.conf
    2. # UPSCABLE <cable> section: change the value to
      UPSCABLE usb
    3. In the next section down, it currently reads DEVICE /dev/ttyS0.  This will not work with a USB cable, so change it to:
      UPSTYPE usb
      DEVICE
      1. (leave DEVICE blank, but put the word DEVICE in there)
    4. Close apcupsd.conf, saving changes
  3. Now, tell the service that your config file has been configured:
    1. gksudo gedit /etc/default/apcupsd
    2. Change ISCONFIGURED=no to ISCONFIGURED=yes
    3. Close, saving changes
  4. Next, restart the apcupsd service:
    1.  sudo service apcupsd restart
  5. Download the apcupsd Webmin module from their downloads page 
    1. At the time of writing, it was named "apcupsd-0.81-2.wbm.gz".
    2. Unzip it to a temp directory
  6. Install the apcupsd module in Webmin
    1. Login to Webmin
    2. Go to Webmin menu > Webmin Configuration > Webmin Modules
    3. Select the [...] button next to "From Local File", and locate where you unzipped it, and install.
    4. Once it is done, click Refresh Modules on the left pane above Logout
    5. Close Webmin in your browser, re-open it, and re-login
  7. Configure apcupsd in Webmin
    1. Go to Others > APC UPS Daemon > Configure Module
    2. Change to the following values:
      1. Configuration file for apcupsd: /etc/apcupsd/apcupsd.conf
      2. Time interval for update screens (in sec): 30
      3. Path to multimon.cgi: /usr/lib/cgi-bin/apcupsd/multimon.cgi
      4. Path to upsfstats.cgi: /usr/lib/cgi-bin/apcupsd/upsfstats.cgi
      5. Path to upsstats.cgi: /usr/lib/cgi-bin/apcupsd/upsstats.cgi
      6. Path to upsimage.cgi: /usr/lib/cgi-bin/apcupsd/upsimage.cgi
      7. Start apcupsd command: /etc/rc.d/init.d/apcupsd start
      8. Stop apcupsd command: /etc/rc.d/init.d/apcupsd stop
  8. That's it.  Just log out of Webmin and back in, go to Others > APC UPS Daemon, and it should look like this:
  9.  
     
You can play around with your config file to make your computer respond to certain battery percentages (for example, shutdown with 10% remaining).  To view all options, use "man apcupsd" in the terminal.

Also, you may want to perform a trial run by unplugging your battery from the wall and seeing what it does.  If you're interested in that sort of thing, there's a good tutorial over at apcupsd.com.

If you have any issues or find this tutorial is inaccurate, please comment below.

No comments:

Post a Comment