Graphing Network Performance with MRTG

VisualThis article guides readers on how to use MRTG in order to display the ADSL traffic of a Cisco 877W router with a little help from SNMP (Simple Network Management Protocol).

MRTG (Multi Router Traffic Grapher), a tool for graphing numerical data, is free and has been written in Perl by Tobi Oetiker. Let’s first check out how much fun installing MRTG can be.

Your Linux distribution will probably include an MRTG package so you will not have any problems installing it. At the time of writing this article, the latest MRTG stable release is version 2.17.4.

Configuring SNMP on a Cisco 877W ADSL router
The first thing to do on the Cisco 877W ADSL router is to turn on SNMP. Then create a SNMP community string that will help you get the required information.
The following commands should be executed on the Cisco router using IOS:

cisco877w#enable
cisco877w#show snmp
%SNMP agent not enabled
cisco877w#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
cisco877w(config)#snmp-server community OpenSourceFY RO
cisco877w(config)#exit

cisco877w#write memory
Building configuration...
[OK]
cisco877w#

The RO community string (OpenSourceFY) permits Get requests only, whereas a RW community string (that is required for this article) allows both Get and Set requests. Allowing Set requests without any reason and without using Cisco Access Lists (ACL) is a security threat.
The following command, that produces plenty of output, will examine if the SNMP router set-up is working as expected:

$ snmpwalk -Os -c OpenSourceFY -v 1 cisco
The cfgmaker utility
The cfgmaker MRTG utility helps create configuration files. It may add unnecessary data that you should clean up later, but its output is a great starting point.
I ran the cfgmaker utility as follows:

$ cfgmaker --global 'WorkDir: /Users/mtsouk/Sites/mrtg' OpenSourceFY@cisco > cisco-MRTG.cfg
$ indexmaker Cisco-MRTG.cfg > index.html

Now you can point your Web browser to the right URL, depending on where you put MRTG’s index.html file, to view MRTG’s information. No image file has been created yet, so the output will look unpleasant.

figure1figure2

Setting up MRTG for the Cisco ADSL router
As the cisco-MRTG.cfg file created by the cfgmaker utility contains unwanted information, I had to clean it up. My final MRTG configuration file is given below:

# /opt/local/bin/cfgmaker --global "WorkDir: /Users/mtsouk/Sites/mrtg" OpenSourceFY@cisco

### Global Defaults
EnableIPv6: no
WorkDir: /Users/mtsouk/Sites/mrtg
### Interface 5 >> Descr: 'Dot11Radio0' | Name: 'Do0' | Ip: '192.168.2.1' | Eth: '00-1d-a2-e7-3f-b0' ###
Target[cisco_5]: 5: OpenSourceFY@cisco:
SetEnv[cisco_5]: MRTG_INT_IP="192.168.2.1"
MRTG_INT_DESCR="Dot11Radio0"

MaxBytes[cisco_5]: 6750000
Title[cisco_5]: Traffic Analysis for WiFi Connection
PageTop[cisco_5]: <h1>Traffic Analysis for WiFi Connection -- cisco877w.mtsouk.local</h1>
<div id="sysdetails">
<table>
<tr><td>System:</td>    <td>cisco877w.mtsouk.local</td></tr>
<tr><td>Maintainer:</td><td></td></tr>
<tr><td>Description:</td>    <td>Dot11Radio0  </td></tr>
<tr><td>ifType:</td>    <td>Radio Spread Spectrum (802.11) (71)</td></tr>
<tr><td>ifName:</td>    <td>Do0</td></tr>
<tr><td>Max Speed:</td><td>6750.0 kBytes/s</td></tr>
<tr><td>Ip:</td><td>192.168.2.1 ()</td></tr>
</table>
</div>

### Interface 15 >> Descr: 'Dialer1' | Name: 'Dialer 1' | Ip: '' | Eth: '' ###

Target[Cisco-linespeed]: 1.3.6.1.2.1.2.2.1.10.14&1.3.6.1.2.1.2.2.1.16.14: OpenSourceFY@cisco:
SetEnv[Cisco-linespeed]: MRTG_INT_IP="" MRTG_INT_DESCR="Dialer1"
MaxBytes[Cisco-linespeed]: 3145728
Title[Cisco-linespeed]: Traffic Analysis for ADSL Internet connection -- Cisco 877W
Legend1[Cisco-linespeed]: Average
Legend2[Cisco-linespeed]:
Legend3[Cisco-linespeed]: Maximum
Legend4[Cisco-linespeed]:
LegendI[Cisco-linespeed]: TX:
LegendO[Cisco-linespeed]: RX:
PageTop[Cisco-linespeed]: <h1>Traffic Analysis for ADSL Internet connection</h1>
<div id="sysdetails">
<table>
<tr><td>System:</td><td>Cisco 877W</td></tr>
<tr><td>Maintainer:</td><td>Mihalis Tsoukalos</td></tr>
<tr><td>Description:</td>    <td>Cisco-linespeed</td></tr>
<tr><td>ifType:</td>    <td>ADSL connection</td></tr>
<tr><td>ifName:</td>    <td>Dialer1</td></tr>
<tr><td>Max Speed:</td><td>250.00 kBytes/s</td></tr>
</table>
</div>

The aforementioned configuration file monitors my ADSL as well as my Wi-Fi traffic. The Wi-Fi connection was automatically found by the cfgmaker utility but setting up the ADSL was more complicated. The Cisco SNMP OIDs (Object Identifiers) that interest me are the following:

•

1.3.6.1.2.1.2.2.1.10.14: returns the incoming traffic for the ADSL connection.
• 1.3.6.1.2.1.2.2.1.16.14: returns the outgoing traffic for my ADSL connection.

Finding those two number sequences is a little difficult, so I will explain how I found them:

 

  • I Googled ‘IF MIB download’ and found the following URL: http://www.oidview.com/mibs/0/IF-MIB.html
  • I knew that I was looking for In and Out Octets and by looking on the Web page, I found that I was interested in sequences
  • 1.3.6.1.2.1.2.2.1.10 (ifInOctets) and 1.3.6.1.2.1.2.2.1.16 (ifOutOctets), respectively.

The last thing to do was adding the desired Cisco interface number at the end of each sequence. The available interfaces can be found by executing the following Cisco IOS command:

cisco877w#show snmp mib ifmib ifindex
ATM0: Ifindex = 6
ATM0-adsl: Ifindex = 12
ATM0-atm layer: Ifindex = 8
ATM0.0-atm subif: Ifindex = 9
FastEthernet0: Ifindex = 1
Null0: Ifindex = 7
Dialer1: Ifindex = 14
FastEthernet1: Ifindex = 2
Virtual-Access1: Ifindex = 15
Vlan1: Ifindex = 13
FastEthernet2: Ifindex = 3
FastEthernet3: Ifindex = 4
Dot11Radio0: Ifindex = 5
ATM0-aal5 layer: Ifindex = 10
ATM0.0-aal5 layer: Ifindex = 11
cisco877w#

In my case, the required interface index number was 14 (Dialer1).
I made MRTG track those two values using the following line:

Target[Cisco-linespeed]: 1.3.6.1.2.1.2.2.1.10.14&1.3.6.1.2.1.2.2.1.16.14: OpenSourceFY@cisco:

Running MRTG
There are two ways of running MRTG, manually or as a cron job. The first way is useful for testing and debugging purposes. After going to the /Users/mtsouk/Sites/mrtg folder, I ran the following command:

$ mrtg cisco-MRTG.cfg

The first time you run it, you will see many error and warning messages due to the fact that all the MRTG output and data files are missing and MRTG has to build them. The next task is to set up MRTG to run as a cron job by adding the following crontab entry:

*/5 * * * */opt/local/bin/mrtg /Users/mtsouk/Sites/mrtg/cisco-MRTG.cfg

This cron command makes MRTG run every five minutes.

MRTG output
Figure 1 shows the output of the MRTG index page as created by the indexmaker utility with the initial cisco-MRTG.cfg file created by the cfgmaker utility.
Figure 2 shows the detailed output that is displayed when you press on one of the images in Figure 1. There is also a ‘Yearly Graph’ that is not shown.

Web Links & Bibliography
[1]     mrtg: http://oss.oetiker.ch/mrtg/
[2]     Cisco MIBs: http://www.cisco.com/public/sw-center/netmgmt/cmtk/mibs.shtml
[3]    SNMP RFCs: http://www.snmp.com/protocol/snmp_rfcs.shtml

All published articles are released under Creative Commons Attribution-NonCommercial 3.0 Unported License, unless otherwise noted.
Open Source For You is powered by WordPress, which gladly sits on top of a CentOS-based LEMP stack.

Creative Commons License.