Thursday, November 19, 2009

MRTG configuration codes

MRTG is an open source tool for basic network monitoring. We can plot network link utilization and CPU performance.

This post is intended for a detailed overview of MRTG configuration on Windows server and adding/managing new devices.

It is quite simple but there are small pieces to put in place. This require high manageability. Here it goes:

Step1. Install MRTG and Perl from Internet. (one time installation)
This can be downloaded freely from Internet. Go to google.com and download the latest one and install in default directory.

Step2. Build the configuration. (each time to add a device)
This step is to add any device in MRTG. Assuming that the devices are reachable from the MRTG server and SNMP port 161 is reachable, we can configure the configuration file. For this purpose i recommend creation of file directory as following.

C:\mrtgdata
conf
output
device1
device2
...
CPU

The configuration code for generating configuration file is :

perl cfgmaker <snmpstring>@192.168.2.2 --global "WorkDir: C:\mrtgdata\output\link\<hostname>" --output c:\mrtgdata\config\<hostname>.cfg

To run this code go to cmd and navigate to C:\mrtg\bin. This code will generate the link utilization HTML files. Make sure bandwidth commands are set on devices, otherwise the utilization value will not be exact.


perl C:\mrtg-2.17.4\mrtg-2.17.4\bin\mrtg C:\mrtgdata\config\<hostname>.cfg

For CPU/Memory/Other utilization:


Please refer individual MIB Values for specific device types. For Cisco devices following link is helpful:

http://www.cisco.com/c/en/us/support/docs/ip/simple-network-management-protocol-snmp/15215-collect-cpu-util-snmp.html

There are varieties of other Parameters which can be monitored: http://www.net-snmp.org/wiki/index.php/TUT:MRTG

An example CPU and Memory Utilization Code could be as following: (Ref: http://www.satsignal.eu/mrtg/performance_howto.php)

#---------------------------------------------------------------
# PC Narvik - Memory
#---------------------------------------------------------------

Target[Narvik-mem]: 1.3.6.1.4.1.9600.1.1.2.19.0&1.3.6.1.4.1.9600.1.1.2.2.0:public@127.0.0.1 * 1024
MaxBytes[Narvik-mem]: 8000000000
Options[Narvik-mem]: integer, gauge, nopercent, growright, unknaszero
YLegend[Narvik-mem]: Memory
ShortLegend[Narvik-mem]: B
LegendI[Narvik-mem]: Used &nbsp;
LegendO[Narvik-mem]: Avail &nbsp;
Legend1[Narvik-mem]: Memory committed
Legend2[Narvik-mem]: Memory available
Title[Narvik-mem]: Narvik Memory
PageTop[Narvik-mem]: <H2>PC Narvik - Memory</H2>

#---------------------------------------------------------------
# PC Narvik - CPU load, dual-core CPU
#---------------------------------------------------------------

Target[Narvik-CPU]: 1.3.6.1.4.1.9600.1.1.5.1.5.1.48&1.3.6.1.4.1.9600.1.1.5.1.5.1.49:public@narvik
MaxBytes[Narvik-CPU]: 100
YLegend[Narvik-CPU]: CPU %
ShortLegend[Narvik-CPU]: %
LegendI[Narvik-CPU]: CPU 1
LegendO[Narvik-CPU]: CPU 2
Legend1[Narvik-CPU]: CPU 1 usage
Legend2[Narvik-CPU]: CPU 2 usage
Options[Narvik-CPU]: integer, gauge, nopercent, growright, unknaszero
Title[Narvik-CPU]: Narvik CPU
PageTop[Narvik-CPU]: <H2>PC Narvik - CPU load</H2>
# If PC Narvik were a single-core CPU, use two instances of object 48, as MRTG requires that 
# you have two variables returned.  You may also want to prevent display of the second output
# line by adding the "no-ouput" option (noo) to the Options line:
Target[Narvik-CPU]: 1.3.6.1.4.1.9600.1.1.5.1.5.1.48&1.3.6.1.4.1.9600.1.1.5.1.5.1.48:public@narvik
Options[Narvik-CPU]: integer, gauge, nopercent, growright, noo
# I found that on a lower-spec PC (Bacchus), returning the CPU twice caused an artificially
# high value to be returned for the second call (presumably the CPU busy processing the first
# request?!), so I actually changed to using the SNMP value: Maximum Number of Process Contexts
# i.e.  .1.3.6.1.2.1.25.1.7.0 (check this on your system using GetIF), which returns integer 0.
Target[Bacchus-CPU]: 1.3.6.1.4.1.9600.1.1.5.1.5.1.48&1.3.6.1.2.1.25.1.7.0:public@192.168.0.4

We can make one cumulative file and one path for all the CPU and Memory output files.

Workdir: C:\mrtgdata\output\cpu

1 comment: