MRTG (Multi Router Traffic Grapher) is monitoring utility, which runs on many platforms and is capable of collecting and graphing statistical information such as network traffic, CPU/Memory/Disk space usage, etc. MRTG can gather information using both SNMP protocol and external scripts. Below are few pieces of my MRTG config file together with scripts, which I felt like sharing.

# MS Win2k server monitoring
# CPU #0
# My script gets the processor load using snmpwalk.  There is a bug in 
# MS SNMP implementation, which changes the processor OID every time SNMP 
# service is restarted.
# My script takes care of it, until your processor is Intel based.  
Target[server1.cpu0]: `/usr/local/bin/mrtg/snmpcpuinfo.perl server1 community 0`
# This will be created under WordDir.  Comes very handy, when you have a
# a handfull of servers.
# Processor load is measured in percent, so 100 will be enough.
MaxBytes[server1.cpu0]: 100
Options[server1.cpu0]: growright,integer,unknaszero,nopercent,gauge
Title[server1.cpu0]: (cpu0)
YLegend[server1.cpu0]: % Used
ShortLegend[server1.cpu0]: %
# You can add here as many processors, as you have on your server.
# eth0
# This is the network interface of our Win2k server.  The easiest way
# to get the correct target is to use cfgmaker, which comes with MRTG.
Options[server1.eth0]: nopercent,growright
Title[server1.eth0]: (eth0)
# users and processes
# Actually, this is not that useful on Win server, though I added it to
# have some consistency with Lin servers pages.
Target[server1.userproc]: `/usr/local/bin/mrtg/snmpuserprocinfo.perl server1 community`
MaxBytes[server1.userproc]: 523444000
Options[server1.userproc]: nopercent,growright,gauge,integer
Title[server1.userproc]: (users and processes)
YLegend[server1.userproc]: Processes/Users
ShortLegend[server1.userproc]: #
# Disk space on drive C
# The index of disk can be obtained from snmpwalk output.
# Now, guess what?  Win2k does not update the value of space used very
# often.  Actually, this value changes only when the SNMP service is
# restarted.  There are different ways of going around this problem. I've
# decided to schedule SNMP service restarts every 10 minutes with 
# this .bat file.
Target[server1.diskc]: `/usr/local/bin/mrtg/snmphddinfo.perl server1 community 2`
# Make sure you put a huge number in here
MaxBytes[server1.diskc]: 100000000000
Options[server1.diskc]: growright,integer,unknaszero,nopercent,gauge
# By default MRTG uses 1000 for Kilo.  Here we change it for a second
kilo[server1.diskc]: 1024
# Disk space is better viewed in Megabytes, Gigabytes, etc.
kMG[server1.diskc]: M,G,T
ShortLegend[server1.diskc]: Bytes
# Linux server monitoring
# Append the following lines to your /etc/snmp/snmpd.conf and restart the
# snmp daemon.  Of course, you should not have hash (#) sign in front of
# those lines.
# ----------
# exec Load-1 /usr/bin/perl /usr/local/sbin/mrtg/loadavg.perl 1
# exec Load-5 /usr/bin/perl /usr/local/sbin/mrtg/loadavg.perl 5
# exec Procs /usr/bin/perl /usr/local/sbin/mrtg/numprocs.perl
# exec MailQ /usr/bin/perl /usr/local/sbin/mrtg/mailqlen.perl
# exec MailQ-Frozen /usr/bin/perl /usr/local/sbin/mrtg/mailqlen.perl frozen
# ----------
# CPU #0
# Actually, I am not measuring CPU load on in Linux servers.  I am pretty
# satisfied with plain Load Average * 100.
Target[server2.cpu0]: `/usr/local/bin/mrtg/snmploadavg.perl server2 community`
# Actually, load average is multiplied by 100, so that the graph looks more
# interesting.
MaxBytes[server2.cpu0]: 10000
Options[server2.cpu0]: growright,integer,unknaszero,nopercent,gauge
Title[server2.cpu0]: (Load average)
YLegend[server2.cpu0]: loadavg
LegendI[server2.cpu0]: 1 min load average
LegendO[server2.cpu0]: 5 min load average    
# You can add here as many processors, as you have on your server.
# eth0
# Network monitoring is configured exactly the same as for Win2k server.
# Still running of cfgmaker is recommended.
Options[server2.eth0]: nopercent,growright
Title[server2.eth0]: (eth0)
# Mailq
# Monitoring of mail queue is essential, since it helps you to see a 
# wide range of problems with your server
# I am using Exim instead of Sendmail,
# so, I am sorry if you are missing mailq command.
Target[server2.mailq]: `/usr/local/bin/mrtg/snmpmailq.perl server2 community`
# Change the number appropriate for your environment
MaxBytes[server2.mailq]: 1000000
Options[server2.mailq]: growright,integer,unknaszero,nopercent,gauge
Title[server2.mailq]: (Mail Queue)
YLegend[server2.mailq]: Messages
ShortLegend[server2.mailq]: Messages
LegendI[server2.mailq]: Frozen
LegendO[server2.mailq]: Total
# users and processes
# Pretty much the same as for Win2k server, but note that "lin" parameter 
# to the script.
Target[server2.userproc]: `/usr/local/bin/mrtg/snmpuserprocinfo.perl server2 community lin`
MaxBytes[server2.userproc]: 523444000
Options[server2.userproc]: nopercent,growright,gauge,integer
Title[server2.userproc]: (users and processes)
YLegend[server2.userproc]: Processes/Users
ShortLegend[server2.userproc]: #
# Disk space on /
Target[server2.disk0]: `/usr/local/bin/mrtg/snmphddinfo.perl server2 community 1`
MaxBytes[server2.disk0]: 100000000000
Options[server2.disk0]: growright,integer,unknaszero,nopercent,gauge
# By default MRTG uses 1000 for Kilo.  Here we change it for a second
kilo[server2.disk0]: 1024
kMG[server2.disk0]: M,G,T
ShortLegend[server2.disk0]: Bytes

You can get all the scripts mentioned in this article as one file.

13 thoughts on “MRTG”

  1. Thank you for making the cpuinfo script. I use it for all my windows 2000 server cpu monitoring.

  2. I don’t understand how you got this to work for you. but…
    I am polling from a Linux server and the command
    snmpwalk $host $community hrProcessorLoad is formated wrong to get data from my Win2k servers.
    It seems to work if I do something like…
    snmpwalk -v1 -c $community $host host.hrDevice.hrProcessorTable.hrProcessorEntry.hrProcessorLoad

    Naturally if I put this info in your script, it still doesn’t work, but it’s a start as far as troubleshooting is concerned.

    I could be wrong.. :-)

  3. Hello. I tried using your Linux drive space script.

    Thank you VERY much for posting this! (I’m looking foward to using it). But I’m having a problem. I’m not getting any values from it. Here’s what happens when I run the script manually. And here’s the variable values that I put into your snmphddinfo.perl script. What am I doing wrong??

    Many many thanks. Outputs below:

    [root@webmail perl]# perl 20040426-snmphddinfo.perl
    [root@webmail perl]#

    [root@webmail perl]# more !$
    more 20040426-snmphddinfo.perl



  4. Is it possible to get it run in Windows ?
    I am using MRTG on a W2K Box.
    I think SNMPWALK is unknown in Windows.
    Does SNMPUTIL.EXE from MS the same as SNMPWALK ?

  5. rjzak@mail:/etc/mrtg> sudo /usr/local/mrtg-2/bin/mrtg /etc/mrtg/mrtg.conf
    ERROR: Target[cpu1][_IN_] ”/etc/mrtg/scripts/snmphddinfo.perl public 2” evaluated to ‘/etc/mrtg/scripts/snmphddinfo.perl public 2’ instead of a number
    ERROR: Target[cpu1][_OUT_] ”/etc/mrtg/scripts/snmphddinfo.perl public 2” evaluated to ‘/etc/mrtg/scripts/snmphddinfo.perl public 2’ instead of a number

    rjzak@mail:/etc/mrtg> scripts/snmphddinfo.perl public 2
    C: Label: Serial Number 84cf40dc

  6. [8] In your mrtg.conf you have to use backquote (`) characters for the
    Target, not double quotes (") like you did. Backquote is usually
    located to the left of button 1 and above the button Tab.

  7. This is too interesting, but I would like to know which is the MIB used to calculate the disk space available in my server. Can any one help me?


  8. Helo !!
    Haw a can get thats archive ?? To done your tutorial ??



  9. Thanks for your help!
    I’ve modified snmphddinfo so it can work in a linux box polling info from nt servers. I leave it here so it can help somebody:



    $msize=int(($blocksize * &getstoragesize) / 1024 / 1024);
    $mused=int(($blocksize * &getusedsize) / 1024 / 1024);

    print “$msize\n”;
    print “$mused\n”;
    print “\n”;

    sub getblocksize {
    $blocksize=`snmpget -v1 -c $community $host hrStorageAllocationUnits.$drive 2>/dev/null`;
    # ($name,$blocks)=split(/ = /, chomp($blocksize));
    $blocks=~s/\ .*//;
    return $blocks;

    sub getstoragesize {
    $storagesize=`snmpget -v1 -c $community $host hrStorageSize.$drive 2>/dev/null`;
    return $size;

    sub getusedsize {
    $usedsize=`snmpget -v1 -c $community $host hrStorageUsed.$drive 2>/dev/null`;
    return $size;

    sub splitnamevalue {
    # print $namevalue;
    ($name,$value)=split(/ = INTEGER: /, $namevalue);
    #print “$name\n”;
    #print “$value\n”;
    return $value;

Leave a Comment