Glad you could stop by the Linux Basement site. Linux Basement is an informational Podcast about Linux, open source software and lots of other wonderful technology. If you want to find out more about open source technologies, subscribe and have a listen!

#linuxbasement is up at irc.freenode.net

MP3 Feed
Ogg Vorbis Feed
MP3 Feed (all episodes)
Ogg Feed (all episodes)

Video blog (not the show!)

 

MRTG on Ubuntu Server

Lets start by installing the goods. Then we will get into the meat of things.

apt-get install snmpd mrtg apache2

When installing MRTG it will ask if you want to only make /etc/mrtg.cfg readable by the MRTG user. In my case, this will be an internal server only, and I do not need to worry about security, so I am going to select NO. If you choose YES, the steps in this tutorial may not work. I have not tested this. However, keep in mind if security is a concern, you may want to go this route and keep MRTG contained in a non-root user environment.
 

Assuming that you want to monitor your networking equipment with MRTG, you need to set up the snmp community on the piece of equipment. Usually its just a matter of enabling snmp, and the default community will be public. If you change the default community to another name, make sure you remember the name for later.

Now lets set up MRTG to read the data.
With Ubuntu server, MRTG will automatically set up /var/www/mrtg. In other distrobutions, it will set it up in a different area, so you will need to change the 'WorkDir:' variable in the following scenario to the directory where MRTG is installed.

I'm going to create an /etc/mrtg directory rather then move the mrtg.cfg file within /etc/ This will make it less confusing in the future.

mkdir /etc/mrtg

mv /etc/mrtg.cfg /etc/mrtg/

Now we run the cfgmaker command to get things up and running:

cfgmaker --global 'WorkDir:/var/www/mrtg' --global 'Options[_]: bits,growright' --output /etc/mrtg/mrtg.cfg public@<yourrouterip>

We need to make sure the following lines are correct in /etc/mrtg/mrtg.cfg If they are not there, add them.

EnableIPv6: no
RunAsDaemon: Yes
Interval: 5
Logdir: /var/log/mrtg

Now run:

indexmaker --output=/var/www/mrtg/index.html /etc/mrtg/mrtg.cfg

Which will build the index so you can view the output.

Then I run this command to set an environmental variable

env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg

and open http://localhost/mrtg/index.html

You should now see an output graph.

crontab -e
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

Let cron pick up stats for an hour or so. After a while, you will see that your graphs are picking up data about your bandwidth.

Here is mine with several cisco 2811 routers configured to show bandwidth.

SNMP and MRTG can monitor much more then bandwidth. For instance you can monitor disk usage, processing use, and more on your servers. There is plenty of documenation on the subject, which leans towards going in and adding snmpd to the servers you want to monitor, setting it up, and then going back and executing the cfgmaker and indexmaker command again so that the new hardware will show up on the page. Because the output of these files is an html page, you can also skin the page and make it look nicer, or embed it into your favorite CMS.

I encourage you to play around with MRTG, because it is the foundation program for a lot of software suites that monitor traffic. One of those, we will talk about next time. Until then, keep hackin.

I used the following articles and papers to create this tutorial:
http://ubuntuforums.org/showthread.php?t=751309