Collect Cisco NBAR Usage Data for MRTG with Perl

Posted on in Programming

Chance asked me to post the Perl script I've been using to collect and graph protocol specific usage information in MRTG. Below, you will find a link to the zip file containing the Perl script.

You can put this script where you like, but you will need to reference it in your mrtg.cfg configuration file. The script accepts the following command-line options:

-c SNMP community string
-h hostname
-i interface SNMP ifIndex
-p comma-separated list of protocols

Additionally, since MRTG has limited graphing capabilities, you will need to specify the which direction of traffic you want to monitor. Acceptable values are IN and OUT.

A picture is worth a thousand words. Here's an example MRTG configuration to monitor BitTorrent compared to total interface traffic.

Target[slap-bt-in]: `/home/mrtg/nbar.pl -h slap2 -c HigracAf6 -i 1 -p bittorrent in`
Options[slap-bt-in]: growright, bits, pngdate, dorelpercent
MaxBytes[slap-bt-in]: 125000000
Title[slap-bt-in]: Austin, TX BitTorrent Traffic: Outgoing
LegendI[slap-bt-in]:  BitTorrent
LegendO[slap-bt-in]:  All
Legend1[slap-bt-in]: BitTorrent Outgoing Traffic
Legend2[slap-bt-in]: All Outgoing Traffic

Target[slap-bt-out]: `/home/mrtg/nbar.pl -h slap2 -c HigracAf6 -i 1 -p bittorrent out`
Options[slap-bt-out]: growright, bits, pngdate, dorelpercent
MaxBytes[slap-bt-out]: 125000000
Title[slap-bt-out]: Austin, TX BitTorrent Traffic: Incoming
LegendI[slap-bt-out]:  BitTorrent
LegendO[slap-bt-out]:  All
Legend1[slap-bt-out]: BitTorrent Incoming Traffic
Legend2[slap-bt-out]: All Incoming Traffic

Hopefully that should be enough to get you going.

Download the latest version.

Slaptijack's Koding Kraken