fld / graph-apcupsd

Bash shell script for logging/graphing apcupsd on Debian jessie.
20 stars 4 forks source link

graph-apcupsd

Bash shell script for logging/graphing apcupsd on Debian jessie.

graph-apcupsd graph-apcupsd

Install

sudo apt-get install rrdtool apcupsd apcupsd-cgi imagemagick git
sudo git clone "git@github.com:fld/graph-apcupsd.git" /etc/apcupsd/

Creating rrdtool database

Create a database for logging: line voltage, load percentage, output voltage, internal temperature, battery voltage and number of transfer events via 'apcaccess status'.

I choose to go with a sampling frequency of 60 seconds, because that is how often 'apcaccess status' updates it's values. The RRA row count of '5256000' is enough for 10-years worth of data.

sudo rrdtool create /etc/apcupsd/apcupsd.rrd \
--step '60' \
'DS:LINEV:GAUGE:120:0:300' \
'DS:LOADPCT:GAUGE:120:0:300' \
'DS:OUTPUTV:GAUGE:120:0:300' \
'DS:ITEMP:GAUGE:120:0:128' \
'DS:BATTV:GAUGE:120:0:50' \
'DS:NUMXFERS:DERIVE:120:0:U' \
'DS:TONBATT:GAUGE:120:0:U' \
'RRA:LAST:0.5:1:5256000'

Cron job

$ sudo crontab -e

Add:

*/1 * * * * /etc/apcupsd/cron-apcupsd.sh
*/1 * * * * /etc/apcupsd/graph-apcupsd.sh

alternatively it could be placed at: /etc/cron.d/graph-apcupsd

Apache configuration

The default Apache configuration for 'apcupsd-cgi' needs to be tweaked to allow images and html content:

<FilesMatch \.png$>SetHandler image/png </FilesMatch>
<FilesMatch \.html$>SetHandler .html</FilesMatch>

For example, on Debian jessie:

/etc/apache2/conf-enabled/serve-cgi-bin.conf:

<IfModule mod_alias.c>
    <IfModule mod_cgi.c>
        Define ENABLE_USR_LIB_CGI_BIN
    </IfModule>

    <IfModule mod_cgid.c>
        Define ENABLE_USR_LIB_CGI_BIN
    </IfModule>

    <IfDefine ENABLE_USR_LIB_CGI_BIN>
        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
            AllowOverride None
            Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
            Require all granted
            <FilesMatch \.png$>
                SetHandler image/png
            </FilesMatch>
            <FilesMatch \.html$>
                SetHandler .html
            </FilesMatch>
        </Directory>
    </IfDefine>
</IfModule>

Viewing statistics

By default, the script generates index.html and __\<time_period>[s].png files to: /usr/lib/cgi-bin/apcupsd/__ which (by default) is accessible at: http://localhost/cgi-bin/apcupsd/