For today's How-To, you'll need:
- Router, firewall or switch that supports SNMP
- Linux (or any *nix box, we're using Ubuntu for today)
Today we'll be setting up a free utility called MRTG (Multi Router Traffic Grapher) to help keep an eye on how much bandwidth we're using. It can run on Windows or Linux (or other *nix operating systems). We'll set it up under Ubuntu Linux to collect data at five minute intervals and draw some pretty graphs.
A SNMP string acts as a simple login for SNMP queries. If you have the right string, you can connect. The read only string is usually set by default to public. Most home network routers actually support SNMP, but you may have to do some hunting to find out how to turn it on. (To get SNMP on the WRT54G, you might want to check out the WiFi-Box firmware.)
For today's How-To you only need to set up a read only string. We suggest changing the read/write string to something no-one will ever guess. (Read / Write access can be used to alter the configuration of a device)
If you followed How-To: Build your own Network Firewall and have a Devil-Linux firewall, then edit /etc/snmpd.conf and add the following:
Don't forget to run save-config when you're done! Once the config it saved, snmpd will start up automatically at boot. For now, start up the snmp deamon by hand. Run the following as root.
Once you've managed to activate SNMP on your network device, head over to your *nix box. We'll walk you through setting everything up under Ubuntu Linux today.
When it's done, pull up a shell and run the following command to set up MRTG.
cfgmaker --global 'WorkDir:/var/www/mrtg' \
--global 'Options[_]: bits,growright' \
--output /etc/mrtg.cfg \
The workdir is where all the data will get stored, the options make things pretty, the output sets the location of the config file, and public is the read only snmp community string you set up. 192.168.1.1 is the ip address on the lan side of the router/firewall/switch you're monitoring. If want to run cfgmaker as a regular user, store the config in your home directory.
If your crazy long command succeeded, you should have a spiffy new config file for MRTG to play with. To get it collecting data every five minutes (plenty for the graphs that MRTG makes) run the following command (as whatever user you want to run MRTG as):
This will edit your crontab. Here you can schedule commands to run at regular intervals. Put the following on one line of the crontab:
0,5,10,15,20,25,30,35,40,45,50,55 * * * * env LANG=C /usr/bin/mrtg /etc/mrtg.cfg --logging /var/log/mrtg.log
Save the file and MRTG will be set to collect data every five minutes. Nice, eh? The env C line is a fix for running MRTG under Ubuntu. It might not be neccesary for your machine, but we needed it.
Permissions are a big part of the game. As long as the user that's running MRTG can read the config file and has write access to the /var/www/mrtg directory, you should be golden. You may wish to create a user just for MRTG and keep everything in its home directory. Then you can point Apache at that directory. Check out the documentation at the MRTG homepage for more.
Good luck, and remember, this will only tell you how much traffic you've got pumping in an out -- it won't prioritize your network traffic over the others' using the pipe. We find the easiest way to take care of that is using MRTG to find the bandwidth hogs, and then walking over to their machines and unplugging them. Enjoy!