Monitor Network Usage with MRTG and DD-WRT
I currently run DD-WRT on a Linksys WRT54GL. One of the great features of DD-WRT is its Simple Network Management Protocol (SNMP) functionality. You can setup a desktop to gather SNMP data from the router and provide it in nice graphical form.
First, you need to configure the router running DD-WRT:
- Login to the DD-WRT web interface by entering the router’s IP address in your browser.
- Select the Services tab.
- Click the Enable radio button under SNMP.
- Enter a description for the location (such as “Home”), a name for the contact (such as “Aaron Gember”), and a name for the router (its hostname is a good choice).
- Click the Apply Settings button.
After DD-WRT is configured, MRTG needs to be configured. All the commands below are run as root. A few may be Fedora specific, but the commands are easily adaptable for other Linux distributions.
- Install MRTG
yum install mrtg
- Create a configuration file for MRTG
cfgmaker --global WorkDir:/var/www/mrtg \ --global 'Options[_]: bits,growright' \ --output /etc/mrtg/mrtg.conf \ public@routernameThe working directory is automatically created when MRTG is installed. The growright option causes graphs to display new data on the right as time progresses. The output file is the default location. Lastly, replace routername with the hostname or IP address of the router.
- Configure the index page to make a nice one stop interface for viewing the graphs produced by MRTG
indexmaker --output=/var/www/mrtg/index.html \ --title=routername --show=day --section=descr \ /etc/mrtg/mrtg.cfgThe title is the text at the top of the index page. The daily graphs are show on the index page, per –show=day; you can alternatively show week, month, or year graphs on the index page. The section headers have the graph description per –section=descr. Lastly, the configuration file created earlier is specified.
- If the Apache web server is not already running, you’ll need to start it:
service httpd restart
You will also want to configure the web server to start whenever the computer starts:
chkconfig httpd on
(There are security risks associated with running a web server, which I do not address here. For the most protection, configure the firewall on the computer to block all incoming HTTP traffic, limiting the viewing of logs to only the computer on which MRTG is running.)
- Lastly, run MRTG once:
env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg
Lastly, you should setup a cron job to update the graphs every 5 minutes. As root, add a cron job to be run by root
crontab -e
and put in the MRTG command (on one line)
0,5,10,15,20,25,30,35,40,45,50,55 * * * * env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg --logging /var/log/mrtg.log &> /dev/null
piping the output to /dev/null so you don’t get an email with the command output every 5 minutes.
To view the graphs, point your browser to http://localhost/mrtg. If you control multiple routers, you can setup MRTG to aggregate the data from all routers into a single web page, but that’s beyond the scope of this post.