Traffic Stats
Server Training - Nagios

In order to get a report of traffic on a router interface you will need to know the name of the interface.  This differs with routers so you may have to use snmpwalk to list the interfaces.  That is what you see in the example below.


Lesson 7 | Lesson 9

snmpwalk -v1 -c public mib-2.interfaces
IF-MIB::ifNumber.0 = INTEGER: 17
IF-MIB::ifIndex.1 = INTEGER: 1
IF-MIB::ifIndex.2 = INTEGER: 2
IF-MIB::ifDescr.1 = STRING: Ethernet0
IF-MIB::ifDescr.2 = STRING: enet-encap
IF-MIB::ifType.1 = INTEGER: ethernetCsmacd(6)
IF-MIB::ifType.2 = INTEGER: other(1)
IF-MIB::ifMtu.1 = INTEGER: 1500
IF-MIB::ifMtu.2 = INTEGER: 1528
IF-MIB::ifSpeed.1 = Gauge32: 100000000
IF-MIB::ifSpeed.2 = Gauge32: 0

Here you can see that the interface is “Ethernet0”.

Once you have that information you will be able to use which is a plugin that you can get from  Download the plugin and place it in the /usr/lib/nagios/plugins directory.  Make sure that it is an executable file with:

chmod 755

Now that you have that ready you can test from the Nagios server using the information about the interface that you have gained. If you get an error message that looks like this:

*ePN /usr/lib/nagios/plugins/ "Use of uninitialized value in scalar chomp at (eval 1) line 186, <FILE> line 1.

If you get the error listed above try changing the text on line 186 from chomp () to


That worked for me.

When you run the command you should get a return.

./ -H -C public -i enet0 -b 10 -u m
Total RX Bytes: 2.94 MB, Total TX Bytes: 2.01 MB<br>Average Traffic: 0.00 kB/s (0.0%) in, 0.00 kB/s (0.0%) out| inUsage=0.0,85,98 outUsage=0.0,85,98 inAbsolut=3012 outAbsolut=2059

The command is set to test a network interface that has the maximum capability of 10 Megabits.

-b 10 -u m

If your interface had the capability of 100 Megabits you would change the command to:

-b 100 -u m

The next step is to set up the command.  Edit the commands.cfg and put this information in that file.

# Check
define command{
command_name check_iftraffic
command_line    $USER1$/ -H $HOSTADDRESS$ -C $USER3$ -i $ARG1$ -b $ARG2$ -u m

Now edit the routers.cfg to add the service.  You may also place this in the service.cfg if you have your routers in that location.  Note that your interface name may be different on your router.

define service{
use             generic-service
host_name       zyxel
service_description     Traffic Load Ethernet0
check_command           check_iftraffic!Ethernet00!10
max_check_attempts      1
normal_check_interval    5
retry_check_interval     5

There may be on problem that could develop since the plugin saves the timestamp and counter status to the /tmp directory so if you tried to test using a user other than nagios that file in the /tmp directory will be owned by the wrong user.  Here is an example:

-rw-r--r--  1 root root   21 Mar 29 09:50 traffic_if1_192.168.5.79

Here the root user was used to test so that must be removed before you activate the plugin.

Basic Nagios Training PDF