# mrtg monitoring script



## jonfr (Jun 3, 2013)

I am having minor issue with mrtg script to monitor network traffic over Ethernet device on my server computer. I am using net-snmp and mrtg.

The mrtg file is working a little, I do get uptime information, computer name. What information I do not get is the information on the Ethernet traffic flowing trough the computer.

The information strings from net-snmp.


```
snmpwalk -v1 -c netsnmp 192.168.1.1 | grep net
SNMPv2-MIB::sysDescr.0 = STRING: FreeBSD saturn.net303.net 9.1-RELEASE FreeBSD 9.1-RELEASE #0 r243826: Tue Dec  4 06:55:39 UTC 2012     root@obrian.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC i386
SNMPv2-MIB::sysObjectID.0 = OID: NET-SNMP-MIB::netSnmpAgentOIDs.8
SNMPv2-MIB::sysName.0 = STRING: saturn.net303.net
IF-MIB::ifType.6 = INTEGER: ethernetCsmacd(6)
HOST-RESOURCES-MIB::hrDeviceDescr.262145 = STRING: network interface usbus0
HOST-RESOURCES-MIB::hrDeviceDescr.262146 = STRING: network interface usbus1
HOST-RESOURCES-MIB::hrDeviceDescr.262147 = STRING: network interface usbus2
HOST-RESOURCES-MIB::hrDeviceDescr.262148 = STRING: network interface usbus3
HOST-RESOURCES-MIB::hrDeviceDescr.262149 = STRING: network interface usbus4
HOST-RESOURCES-MIB::hrDeviceDescr.262150 = STRING: network interface vr0
HOST-RESOURCES-MIB::hrDeviceDescr.262151 = STRING: network interface plip0
HOST-RESOURCES-MIB::hrDeviceDescr.262152 = STRING: network interface lo0
HOST-RESOURCES-MIB::hrDeviceDescr.262153 = STRING: network interface tun0
HOST-RESOURCES-MIB::hrSWRunParameters.1203 = STRING: "-p /var/run/net_snmpd.pid -c /usr/local/share/snmp/snmpd.conf,/etc/snmpd.conf -a"
HOST-RESOURCES-MIB::hrSWRunParameters.75328 = STRING: "-v1 -c netsnmp 192.168.1.1"
HOST-RESOURCES-MIB::hrSWRunParameters.75329 = STRING: "net"
HOST-RESOURCES-MIB::hrSWInstalledName.41 = STRING: "nettle-2.7"
HOST-RESOURCES-MIB::hrSWInstalledName.93 = STRING: "net-snmp-5.7.2_2"
```

The mrtg script that I am using.


```
WorkDir: /usr/local/www/apache24/data/mrtg
Options[_]: bits,growright

Target[localhost_server]: 2:netsnmp@192.168.1.1:
SetEnv[localhost_server]: MRTG_INT_IP="192.168.1.1" MRTG_INT_DESCR="server"
MaxBytes[localhost_server]: 12500000
Title[localhost_server]: Title
PageTop[localhost_server]: <H1>Server Network Traffic</H1>
 <TABLE>
   <TR><TD>System:</TD>     <TD>System</TD></TR>
   <TR><TD>Maintainer:</TD> <TD>Maintainer</TD></TR>
   <TR><TD>Description:</TD><TD>Lan  </TD></TR>
   <TR><TD>ifType:</TD>     <TD>eth0</TD></TR>
   <TR><TD>ifName:</TD>     <TD></TD></TR>
   <TR><TD>Max Speed:</TD>  <TD>100 Mbits/s</TD></TR>
   <TR><TD>Ip:</TD>         <TD>Ip()</TD></TR>
 </TABLE>
```

When the mrtg script is run with cron. I get this error message.


```
SNMP Error:
Received SNMP response with error code
  error status: noSuchName
  index 2 (OID: 1.3.6.1.2.1.2.2.1.16.262150)
SNMPv1_Session (remote host: "192.168.1.1" [192.168.1.1].161)
                  community: "netsnmp"
                 request ID: 1419061404
                PDU bufsize: 8000 bytes
                    timeout: 2s
                    retries: 5
                    backoff: 1)
 at /usr/local/lib/perl5/site_perl/5.12.4/SNMP_util.pm line 492
SNMPGET Problem for ifInOctets.262150 ifOutOctets.262150 sysUptime sysName on netsnmp@192.168.1.1::::::v4only
 at /usr/local/bin/mrtg line 2330
2013-06-03 01:49:04: ERROR: Target[localhost_server][_IN_] ' $target->[0]{$mode} ' did not eval into defined data
2013-06-03 01:49:04: ERROR: Target[localhost_server][_OUT_] ' $target->[0]{$mode} ' did not eval into defined data
```

I have been trying to find mrtg script samples for this online. I have not had any luck so far.

Thanks for the help.


----------



## phoenix (Jun 3, 2013)

Your target string is completely wrong. Lol.

`ifInOctets.2&ifOutOctets.2:netsnmp@192.168.1.1`

You have to specify the entire MIB name, including the number.

The part before the & is for incoming traffic, the part after the &is for outgoing traffic.

The part after the : tells it which host to contract and which community string to use.


----------



## jonfr (Jun 3, 2013)

I guess it is supposed to look something like this.


```
LoadMIBs: /usr/local/share/snmp/mibs/UCD-SNMP-MIB.txt
Target[freebsd.cpu]:ssCpuRawUser.0&ssCpuRawUser.0:netsnmp@192.168.1.1 + ssCpuRawSystem.0&ssCpuRawSystem.0:netsnmp@192.168.1.1 + ssCpuRawNice.0&ssCpuRawNice.0:netsnmp@192.168.1.1
```

This is what I use to track CPU usage on my FreeBSD server. This string is what I used in Gentoo Linux, it works for my Gentoo Linux monitoring (desktop computer). I do not know why that is.


----------



## phoenix (Jun 4, 2013)

Put the target string I posted into your configuration file, and it will work.


----------



## jonfr (Jun 4, 2013)

phoenix said:
			
		

> Put the target string I posted into your configuration file, and it will work.



I did do so and the configuration file looks like this now.


```
WorkDir: /usr/local/www/apache24/data/mrtg
Options[_]: bits,growright

LoadMIBs: /usr/local/share/snmp/mibs/UCD-SNMP-MIB.txt

Target[localhost_server]: ifInOctets.2&ifOutOctets.2:netsnmp@192.168.1.1
SetEnv[localhost_server]: MRTG_INT_IP="192.168.1.1" MRTG_INT_DESCR="server"
MaxBytes[localhost_server]: 12500000
Title[localhost_server]: Title
PageTop[localhost_server]: <H1>Server Network Traffic</H1>
 <TABLE>
   <TR><TD>System:</TD>     <TD>System</TD></TR>
   <TR><TD>Maintainer:</TD> <TD>Maintainer</TD></TR>
   <TR><TD>Description:</TD><TD>Lan  </TD></TR>
   <TR><TD>ifType:</TD>     <TD>eth0</TD></TR>
   <TR><TD>ifName:</TD>     <TD></TD></TR>
   <TR><TD>Max Speed:</TD>  <TD>100 Mbits/s</TD></TR>
   <TR><TD>Ip:</TD>         <TD>Ip()</TD></TR>
 </TABLE>
```

It still does not work for the ethernet traffic (vr0). All I get is the uptime information.


----------



## chatwizrd (Jun 4, 2013)

Just use net-mgmt/cacti*,* it*'*s far better.


----------



## jonfr (Jun 9, 2013)

chatwizrd said:
			
		

> Just use net-mgmt/cacti*,* it*'*s far better.



While I am testing net-mgmt/cacti. I also want to get mrtg up and running for this monitoring. All I currently get from FreeBSD is the uptime, but no traffic data from vr0. I still do not know what the problem is, and because of this. I cannot fix it.


----------



## jonfr (Jun 10, 2013)

phoenix said:
			
		

> Put the target string I posted into your configuration file, and it will work.



I found the issue with the string, I needed to change "2" to "6" (vr0 interface number) and then it started to work.

I am also going to apply this to monitor Internet traffic over tun0, that is the tunnel for my IPv6 connection.


----------



## phoenix (Jun 10, 2013)

Sorry, figure you knew how to differentiate between interfaces.

This will show you the names of the interfaces, and what the index number is for each of them.  Use the index number to refer to that interface when querying other MIBs:

```
# snmpwalk -v 2c -c netsnmp 192.168.1.1 ifDescr
```

You'll get output similar to:

```
IF-MIB::ifDescr.1 = STRING: bge0
IF-MIB::ifDescr.2 = STRING: bge1
IF-MIB::ifDescr.3 = STRING: em0
IF-MIB::ifDescr.4 = STRING: em1
IF-MIB::ifDescr.5 = STRING: em2
IF-MIB::ifDescr.6 = STRING: em3
IF-MIB::ifDescr.7 = STRING: lo0
```

If you do a similar snmpwalk of the ifInOctets MIB, you'll get:

```
# snmpwalk -v 2c -c netsnmp 192.168.1.1 ifInOctets
IF-MIB::ifInOctets.1 = Counter32: 0
IF-MIB::ifInOctets.2 = Counter32: 0
IF-MIB::ifInOctets.3 = Counter32: 3674829526
IF-MIB::ifInOctets.4 = Counter32: 1450313159
IF-MIB::ifInOctets.5 = Counter32: 1902874955
IF-MIB::ifInOctets.6 = Counter32: 1055520394
IF-MIB::ifInOctets.7 = Counter32: 673081512
```

The *.#* is used to indicate which interface is being used (*.4 is em1, *.7 is lo0, etc).  So, in your Target line, you specify the index that corresponds to the interface you want.

Each MIB has a Descr (or similar) that shows you the "normal" names for things, and the index value to query.


----------



## jonfr (Jun 12, 2013)

Thanks. While I have been a Gentoo Linux user since 2003, I still have to adjust to using FreeBSD. There are a lot of differences between the systems that I do not properly of yet.


----------

