Bash shell script for logging/graphing apcupsd on Debian jessie.
sudo apt-get install rrdtool apcupsd apcupsd-cgi imagemagick git
sudo git clone "git@github.com:fld/graph-apcupsd.git" /etc/apcupsd/
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'
$ 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
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>
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/