Continuing on our open source network monitoring theme, this article looks at installing and configuring MRTG (The Multi Router Traffic Grapher) that allows you to graph various SNMP enabled network devices.
In case you haven’t already read it, check out our article on building a Linux server (running openSUSE 11.0) from scratch and installing Nagios.
This time (using the same VM) we will be installing MRTG so that we can graph network utilisation on a Windows 2003 Server that serves as a gateway on our network.
More specifically, we want to monitor traffic on both internal and external network interfaces so that we can easily see all internet traffic from the server and internal traffic to the server.
The same principles in this article can be used for any SNMP enabled device, such as routers, switches and printers.
Enabling SNMP on a Windows machine
First of all we need to make sure that SNMP is enabled on our Windows machine. To do this:
- Open Control Panel
- Open Add / Remove Programs
- Open Add / Remove Windows Components
- Select “Management and Monitoring Tools” and click the “Details” button
- Check “Simple Network Management Protocol” and click OK. You may need to insert your original Windows setup CD/DVD in order to complete the installation.

With SNMP installed we now need configure the service to allow our SNMP agent (the Linux server running MRTG) to retrieve data from our network interfaces. To do this:
- Go to Start > Run
- In the run box type “services.msc” (without the quotes) to bring up the Services MMC snapin.
- Right click the “SNMP Service” service and choose “Properties”

- Click on the “Traps” tab and enter the community name “public” (for greater security you should use a more complex community name)
- In your Trap Destinations, add the IP Address or Host Name of your Linux server.

- Finally right click the “SNMP Service” service and select “Restart” in order to apply these settings.
Now that we have enabled SNMP on our Windows server we can set up MRTG on our Linux box:
- Boot up your Linux server if it is not up already
- Log in and su to root
- Open up YaST
- Select Software > Software Management
- Change your Filter type to “Search”, enter the search term “mrtg” and Search
- MRTG should appear in your results. Mark it for installation by selecting and pressing your SPACEBAR

- Accept the changes to complete the installation.
Once complete, quit out of YaST to return to the shell.
Configuring MRTG
The runtime behaviour of MRTG is governed by a configuration file. Run-of-the-mill configuration files can be generated with the cfgmaker. Cfgmaker is a utility that creates MRTG configuration files based on information pulled from a router or another SNMP manageable device.
This article only touches on what can be graphed with MRTG. You can view the complete documentation at http://oss.oetiker.ch/mrtg/doc/index.en.html.
We are going to create our configuration files from scratch.
First create a directory on the apache web server to host the files:
LinuxServer1:~ # mkdir /srv/www/htdocs/mrtg
Then create a new directory “/etc/mrtg” to store our config files:
LinuxServer1:~ # mkdir /etc/mrtg
Next we need to create our configuration file:
LinuxServer1:~ # vi /etc/mrtg/winserver.cfg
Add the following contents to the file:
# Global Settings
EnableIPv6: no
WorkDir: /srv/www/htdocs/mrtg
Options[_]: bits,growright
# Targets
Target[WinServer-internal-eth]: -/192.168.0.1:public@192.168.0.1
MaxBytes[WinServer-internal-eth]: 125000
Title[WinServer-internal-eth]: Windows Server Internal NIC
PageTop[WinServer-internal-eth]: <h1>Windows Server Internal NIC - 192.168.0.1</h1>
Target[WinServer-external-eth]: -/192.168.160.1:public@192.168.160.1
MaxBytes[WinServer-external-eth]: 125000
Title[WinServer-external-eth]: Windows Server External NIC
PageTop[WinServer-external-eth]: <h1>Windows Server External NIC - 192.168.160.1</h1>
Save the file by issuing the command:
:wq
Explanation
- WorkDir - Specifies where the logfiles and the webpages should be created.
- Target - Tells mrtg what it should monitor – the name inside the square brackets can be anything you decide
- MaxBytes - The maximum value either of the two variables monitored are allowed to reach. For monitoring router traffic this is normally the bytes per second this interface port can carry.
- Title - Title for the HTML page which gets generated for the graph.
- Things to add to the top of the generated HTML page. Note that you can have several lines of text as long as the first column is empty.
Now that we have created our configuration file we can run mrtg. We will add this as a cron tab later on so that it runs automatically every 5 minutes.
For now type the following command:
LinuxServer1:~ # mrtg /etc/mrtg/winserver.cfg
You will probably see a number of errors concerning the reading/removal of log files. These are normal when processing a configuration file for the first time.
Next we can use the indexmaker tool to create the index files for our web site. Since we may be running this command frequently (necessary after making changes to your config file) create the following shell script in /srv/www/htdocs/mrtg:
vi /srv/www/htdocs/mrtg/newindex.sh
Add the following and save the file:
indexmaker /etc/mrtg/winserver.cfg --output /srv/www/htdocs/mrtg/index.html --title My_Network_Traffic
Note: Title cannot have spaces in it.
Run the following command:
chmod 770 /srv/www/htdocs/mrtg/newindex.sh
Now whenever we want to generate a new index page we just run:
LinuxServer1:~ # /srv/www/htdocs/mrtg/newindex.sh
After running the above command, browse to http://<yourserverip>/mrtg/
You should see a couple of graphs on your page. These graphs are currently empty as we have only run mrtg once against these targets. To set this to run automatically every 5 minutes, open /etc/crontab:
vi /etc/crontab
And add the following line:
*/5 * * * * root mrtg /etc/mrtg/winserver.cfg
Save with the following command:
:wq
Sure enough, after leaving enough time for the Linux server to sample the snmp data, we have a nice graphs showing the network utilisation:

It's as simple as that. Be sure to read the complete documentation at http://oss.oetiker.ch/mrtg/doc/index.en.html.
Comments
Comment this article