Using MRTG on Debian
In yet another episode of ‘how to run broken packages on Debian’ this is the MRTG episode.
I have spent some time earlier on getting mrtg to work on my server but by now it has sent me hundreds of emails already telling me it’s not working properly, telling me things like:
Constant subroutine SNMP_Session::AF_INET6 redefined at /usr/share/perl/5.12/Exporter.pm line 64. at /usr/share/perl5/SNMP_Session.pm line 149
As I never gave mrtg much time on installation, let’s try and do this a bit more structurally, as MRTG, but mostly the RRD database being used as an engine for it, is really quite a nice tool that deserves some more attention. So, I removed the mrtg package first to start again from scratch:
omega:~# dpkg --purge mrtg
Reinstalling
With the mrtg package now removed, let’s reinstall and analyze what’s happening exactly:
omega:~# apt-get install mrtg
The package install asks whether the /etc/mrtg.cfg should be readable by root-only as making it readable by others is a security risk. I’m not sure why bother to ask then, so I said to make it readable by root-only. The package install recommends installing mrtg-contrib as well, so let’s:
omega:~# apt-get install mrtg-contrib
Configuration
The config file /etc/mrtg.cfg mentioned in the install is very simple indeed as it only specifies the WorkDir, the WriteExpires and the Title.
After the install there doesn’t appear to be any daemon running, nor is there an init RC file for MRTG. Fortunately we do find an /etc/cron.d/mrtg file:
*/5 * * * * root if [ -x /usr/bin/mrtg ] && [ -r /etc/mrtg.cfg ]; then mkdir -p /var/log/mrtg ; env LANG=C /usr/bin/mrtg /etc/mrtg.cfg 2>&1 | tee -a /var/log/mrtg/mrtg.log ; fi
So we see mrtg gets fired up every 5 minutes through cron. Looking at this we expect to find something in /var/log/mrtg as well, and indeed there’s a logfile which contains repetitive error messages seen earlier. As the script runs as root, we can also try reproducing this from the command line:
omega:/etc/cron.d# env LANG=C /usr/bin/mrtg /etc/mrtg.cfg Constant subroutine SNMP_Session::AF_INET6 redefined at /usr/share/perl/5.12/Exporter.pm line 64. at /usr/share/perl5/SNMP_Session.pm line 149 Prototype mismatch: sub SNMP_Session::AF_INET6 () vs none at /usr/share/perl/5.12/Exporter.pm line 64. at /usr/share/perl5/SNMP_Session.pm line 149 Constant subroutine SNMP_Session::PF_INET6 redefined at /usr/share/perl/5.12/Exporter.pm line 64. at /usr/share/perl5/SNMP_Session.pm line 149 Prototype mismatch: sub SNMP_Session::PF_INET6 () vs none at /usr/share/perl/5.12/Exporter.pm line 64. at /usr/share/perl5/SNMP_Session.pm line 149 Constant subroutine SNMPv1_Session::AF_INET6 redefined at /usr/share/perl/5.12/Exporter.pm line 64. at /usr/share/perl5/SNMP_Session.pm line 608 Prototype mismatch: sub SNMPv1_Session::AF_INET6 () vs none at /usr/share/perl/5.12/Exporter.pm line 64. at /usr/share/perl5/SNMP_Session.pm line 608 Constant subroutine SNMPv1_Session::PF_INET6 redefined at /usr/share/perl/5.12/Exporter.pm line 64. at /usr/share/perl5/SNMP_Session.pm line 608 Prototype mismatch: sub SNMPv1_Session::PF_INET6 () vs none at /usr/share/perl/5.12/Exporter.pm line 64. at /usr/share/perl5/SNMP_Session.pm line 608
Just lovely…
Fixing the bug wasn’t very difficult. I found a Debian bug report which alas didn’t include a fix yet; however I found a fix here. Voila, now I have mrtg running, let’s see how to configure it.
