mrtg on FreeBSD

Unless you want SNMP (no you don't) you'll want to copy the following files into /usr/local/bin/:

  • ?errors2mrtg
  • ?netstat2mrtg
  • ?pkts2mrtg

Install mrtg:

pkg install mrtg

Configure mrtg by editing /usr/local/etc/mrtg/mrtg.cfg which can be based on mrtg.cfg in this directory. Do create the output directory too:

mkdir -p /usr/local/www/mrtg

Add a crontab entry:

*/5 *   * * *   root    /usr/local/bin/mrtg /usr/local/etc/mrtg/mrtg.cfg

If you want to be able to view the graphs, you can install a web server binding to localhost and generate an index file:

pkg install thttpd
cat > /usr/local/etc/thttpd.conf << EOF
user=www
dir=/usr/local/www/mrtg
logfile=/var/log/thttpd.log
pidfile=/var/run/thttpd.pid
host=127.0.0.1
EOF
sysrc thttpd_enable=yes
service thttpd start
/usr/local/bin/indexmaker --title "MRTG ${THIS_SITE-I_DIDNT_READ}" /usr/local/etc/mrtg/mrtg.cfg > /usr/local/www/mrtg/index.html

To access the web server from your local machine, something like this can be handy to have in ~/.bashrc:

alias tunnel-dfri-traffic-graphs='tunnel-rs02web; tunnel-rs03web; tunnel-rs3web; tunnel-rs4web'
alias tunnel-rs02web='ssh -NfL 47802:localhost:80 rs0-2.dfri.net'
alias tunnel-rs03web='ssh -NfL 47803:localhost:80 rs0-3.dfri.net'
alias tunnel-rs3web='ssh -NfL 4783:localhost:80 rs3.dfri.net'
alias tunnel-rs4web='ssh -NfL 4784:localhost:80 rs4.dfri.net'