Considered upgrading your DSL/Cable modem connection lately? Been wondering just how much of that high speed Internet connection you've been using? (Or if one of your kids or housemates is eating up all the bandwidth with BitTorrent again.) Today we'll show you how to use some handy free tools to keep an eye on your precious bandwidth. Hey, it just might save you from having to bleach your eyes if you walk in after Bob's download finishes.

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)
If you're not familiar with SNMP, never fear, Engadget's here. It's a handy protocol used to collect device information over a network connection. Seriously, you don't need to fully understand it for today's How-To.

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.

First, we'll need to configure SNMP on whatever firewall, router or network switch you have. (Managed switches support it, but el cheapo hubs won't.) It's not hard, all you need to do is turn on SNMP if there's an option, and configure the SNMP strings.

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:
syslocation "home"
syscontact you@yourdomain
rocommunity public

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.
/etc/init.d/snmpd start


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.

Open up Synaptic and search for mrtg. Install it, along with the contrib package. While you're in there, install a copy of Apache web server. (No, it doesn't really matter which version. Um, we like Apache2. yeah.)

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 \
public@192.168.1.1

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):
crontab -e
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.

Once it runs a few times, point your web browser at the machine you're running mrtg on. http://localhost/mrtg if you're on your Linux box. There you'll find a collection of images and html pages. You might want to view these or build an index page with links to the images for each interface you want to keep an eye on.

Troubleshooting suggestions:
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!