Capturing data from network routers and systems can be both interesting and enlightening. This data is sometimes not so easy to obtain, but using tools like MRTG (available here) can make it easier to both obtain and monitor. MRTG, which stands for Multi Router Traffic Grapher, can be used to graph more than just traffic data from your router; but here, we'll look at an initial setup to allow MRTG to read data from a Linksys BEFSR81 router.
The first step is to enable SNMP access in the Linksys router by going to the administrative Web interface and selecting Administration. Here you can enable SNMP and provide a few settings; the important one right now is just to turn SNMP support on.
If your distribution ships with MRTG, install the package. If not, download it and be sure you have the development libraries for GD, libpng, and zlib installed. You will also need a working perl installation.
Once MRTG is installed, create an initial configuration file:
# cfgmaker -global 'WorkDir: /var/www/html/mrtg' --output=/etc/mrtg.cfg \
--global 'Options[_]: bits, growright' --output=/etc/mrtg.cfg \
This really long command is all that's needed to tell MRTG to poll data from the router using SNMP. All the MRTG data will be viewable in the /var/www/html/mrtg directory. The email@example.com in the above snippet is the Get Community setting in the Linksys router and the IP address of the router.
Once this finishes and the configuration file is created, it's time to run MRTG and collect some data. On the first two runs you'll get errors; these can safely be ignored as MRTG is complaining about the lack of history data. Subsequent runs should complete without error. To run MRTG enter:
# mrtg /etc/mrtg.cfg
To create the Web page data, use the indexmaker tool like this:
# indexmaker -output=/var/www/html/mrtg/index.html -
title="Network MRTG" -sort=title
When you browse the /mrtg/ directory on the server, this code will make the index.html file display the MRTG data; links on specific graphs will allow you to view further detailed data.
Finally, to update MRTG's data in a consistent fashion, use cron to execute MRTG every 5 minutes. This can be done with the following crontab entry:
*/5 * * * * /usr/bin/mrtg /etc/mrtg.cfg --logging /var/log/mrtg.log
MRTG is extremely powerful, and this is just the tip of the iceberg. There are hundreds of things you can use MRTG to graph, but the first step is getting it up and running. If you use a Linksys router, or any other router that supports SNMP, you can start with graphing network and bandwidth usage.
Delivered each Tuesday, TechRepublic's free Linux NetNote provides tips, articles, and other resources to help you hone your Linux skills. Automatically sign up today!
Vincent Danen works on the Red Hat Security Response Team and lives in Canada. He has been writing about and developing on Linux for over 10 years and is a veteran Mac user.