The Multi Router Traffic Grapher

Version 2.2, 24 April 1997

Programming by Tobias Oetiker <oetiker@ee.ethz.ch>
Dave Rand <dlr@bungi.com>
and a number of other people from the Global-Village
Documentation by Tobias Oetiker <oetiker@ee.ethz.ch>

Contents
What is the Multi Router Traffic Grapher

The Multi Router Traffic Grapher (MRTG) is a tool to monitor the traffic load on network-links. MRTG generates HTML pages containing GIF images which provide a LIVE visual representation of this traffic. Check http://www.ee.ethz.ch/stats/mrtg/ for an example. MRTG is based on Perl and C and works under UNIX and Windows NT. MRTG is being successfully used on many sites arrond the net. Check the MRTG-Site-Map.

MRTG is available under the GNU PUBLIC LICENSE.
The only thing I would like to ask happy users to do, is to
send a Picture Postcard to:
Tobias Oetiker, D-ELEK, ETH Zentrum, CH-8092 Zurich, Switzerland

MRTG consists of a Perl script which uses SNMP to read the traffic counters of your routers and a fast C program which logs the traffic data and creates beautiful graphs representing the traffic on the monitored network connection. These graphs are embedded into webpages which can be viewed from any modern Web-browser

In addition to a detailed daily view, MRTG also creates visual representations of the traffic seen during the last seven days, the last four weeks and the last twelve months. This is possible because MRTG keeps a log of all the data it has pulled from the router. This log is automatically consolidated, so that it does not grow over time, but still contains all the relevant data for all the traffic seen over the last two years. This is all performed in an efficient manner. Therefore you can monitor 50 or more network links from any halfway decent UNIX box.

MRTG is not limited to monitoring traffic though, it is possible to monitor any SNMP variable you choose. You can even use an external program to gather the data which should be monitored via MRTG. People are using MRTG, to monitor things such as System Load, Login Sessions, Modem availability and more. MRTG even allows you to accumulate two or more data sources into a single graph.

Highlights of MRTG
  1. Works on most UNIX platforms and Windows NT
  2. Uses Perl for easy customization
  3. Has a highly portable SNMP implementation written entirely in Perl thanks to Simon Leinen. There is no need to install any external SNMP package.
  4. MRTG's logfiles do NOT grow. Thanks to the use of a unique data consolidation algorithm.
  5. MRTG comes with a semi-automatic configuration tool.
  6. MRTG's query engine checks for port reconfigurations on the router and warns the user when they occur.
  7. Time critical routines are written in C thanks to the initiative of Dave Rand my Co-Author
  8. Graphics are generated directly in GIF format, using the GD library by Thomas Boutell.
  9. The look of the webpages produced by MRTG is highly configurable.
  10. MRTG is available under the GNU PUBLIC LICENSE.
History of MRTG

In 1994 I was working at a site where we had one 64kbit line to the outside world. Obviously everybody was interested in knowing how the link was performing. So I wrote a quick hack which created a constantly updated graph on the web, showing the traffic load on our Internet link. This eventually evolved into a rather configurable Perl script called MRTG-1.0 which I released in spring 1995. After a few updates I left my job at DMU, to start work at the Swiss Federal Institute of Technology. Due to lack of time I had to put MRTG aside. One day in January of 1996, I received email from Dave Rand asking if I had any ideas why MRTG was so slow. Actually I did. MRTG's programming was not very efficient and it was written entirely in Perl. After a week or so, Dave wrote back to me and said he had tried what I had suggested for improving MRTG's speed. Since the changes did not help much, he had decided to rewrite the time-critical sections of MRTG in C. The code was attached to his email. His tool increased the speed of MRTG by a factor of 40! This got me out of my 'MRTG ignorance' and I started to spend my spare time developing of MRTG-2.

Soon after MRTG-2 development had begun I started to give beta copies to interested parties. In return I got many feature patches, a lot of user feedback and bug fixes. The product you are getting now is the result of a wonderful collaboration of many people. I would like to take this opportunity to thank them all. (See the files CHANGES and CONTRIBUTORS in the MRTG distribution.)

Release Notes
Version 2.2
Lots of new and exciting things in the contrib area.
Made graphs in indexmaker generated pages clickable
made mrtg observe order of routers in cfg file .... as suggested by Mick Ghazey
Added timezone configurable to set a timezone per router. Details in mrtg.cfg-dist as suggested by Jun (John) Wu
Added MaxBytes sanity check ....
Fixed portability problem of Makefile under IRIX
Version 2.1
Added 100BaseVG iftyp to cfgmaker
Added rdlog2 by Phillip Simonet. This tool transforms a xfig network map into a clickable gif with colorcoded representation of the current load of your network links. The information for the colorcoding is taken from the mrtg log files.
From: "Peter W. Osel" <pwo@christl.hl.siemens.de> A perl script to get roundtrip delays to hosts by sending a ping to them. Added to contrib.
Fixed rounding Bug in rateup.c which caused it to scale graphs with small values incorrectly ...
Allowed any character except @ and \s to be used in a community string ...
Fixed two instances where variables were declared twice (my($var)) within the same scope. Late perl5.003 versions do not like that ... and it was wrong anyway. This happens both in SNMP_Session.pm and mrtg.
When using the Directory option in connection with [^] a stray space gets added to the path. This is now removed with s/\s//g ... spaces in path names are stupid anyway.
Getting and Installing MRTG
  1. Get the latest Version of MRTG from:
    http://www.ee.ethz.ch/~oetiker/webtools/mrtg/pub/

  2. Get and compile the GD library by Thomas Boutell:
    http://www.boutell.com/gd/

  3. Make sure you have Perl Version 5.003 or later on your system:
    http://www.perl.com/perl/info/software.html

  4. Edit the MRTG Makefile to fit your system. At least change the PERL and GD_LIB variables.
    Then use make rateup to create the rateup binary.
    And make substitute to insert the path of your Perl binary into the perlscripts which come with MRTG.

  5. Decide where MRTG should store the webpages it creates. Copy the mrtg*.gif files into this directory. They will be referenced in the generated webpages. You may also want to move the readme.html file to this directory so that you have the docs handy when ever you need them.

  6. All the other files from the MRTG distribution should go into your MRTG binary directory. This directory can be anywhere because MRTG will find its location upon startup. The following files are required to be in MRTG-bin: BER.pm, SNMP_Session.pm, mrtg, rateup.

  7. Create your personal mrtg.cfg file. You can use mrtg.cfg-dist as an example. It is extensively commented. See the Configuration Hints section for some further help. The difficult part in creating the configuration file is getting your router-port assignment correct. To help you with this, the cfgmaker tool will generate all the router specific parts of your configuration file.

    cfgmaker <community>@<router-host-name or IP>
    If you don't know the community of your router, try public as community name.

  8. If you are upgrading from any pre 2.0 version of MRTG, you need to run the convert script with your old logfiles, in order to bring them over to the mrtg-2.0 log-file-format.

  9. Try to start MRTG. Type ./mrtg mrtg.cfg on the command line, while you are in your MRTG binary directory. MRTG will now parse your configuration file, and complain if you have introduced any unknown keywords or structures. If MRTG is happy with the cfg file, it starts gathering traffic data from the routers you have specified. With this information it will then start the rateup tool which will create a logfile and a traffic graph GIF for each Target. When you start MRTG for the very first time, rateup will complain that it can not find any logfiles and the graphs generated will look rather empty. Just ignore the complaints. If you remove the empty graphs, and run MRTG again, rateup will create new graphs which look better.

  10. Integrate MRTG into your crontab. Just add the following line to your crontab file to have MRTG run every 5 minutes (The line is broken for readability only. Replace the backslash in the first line with the second line):

    0,5,10,15,20,25,30,35,40,45,50,55 * * * * \
    <mrtg-bin>/mrtg <path to mrtg-cfg>/mrtg.cfg

Configuration Tips
  • If you are monitoring a number of links, you might want to create an overview page. For our own site I have created the indexmaker script, which you can use to create a html page containing hrefs that point to your individual traffic statistics pages. Note, that you need to edit this script for your purposes. The script you got, includes our Universities Logo (http://www.ee.ethz.ch/eth.199x32.gif) into the page.

    indexmaker <mrtg.cfg> <regexp for router-names>

  • If you are monitoring many targets, use the special target names '^' and '$' to prepend or append text to any of the Keywords in the sections below. Note that the definition of the '^' and '$' targets are position dependant. They always influence the lines bleow in the cfg file.

  • Since MRTG updates it's graphs every 5 minutes, you may experience problems with proxy caches and local Netscape browser caches. Sometimes these caches will return the old cached graphics instead of the real and updated versions from the webserver.

    If you are running the apache webserver, you can use the WriteExpire Keyword in the mrtg.cfg file. With this, mrtg will create *.meta files for each gif and html page. These files will contain 'Expire' headers which the Apache webserver can ship out together with the gif and html pages (Use to MetaDir keyword in the apache config file to enable this). With the information from the expire headers, Netscape and all the proxy caches will know when they have to fetch a new version of the file from your website and when they can use their cached version.

  • Although MRTG's primary use is traffic monitoring, you can observe any SNMP variable you want. People are using it to monitor ModemBanks, ServerLoad, ErrorRates on Interfaces and many other things. If you are using MRTG for something other than traffic monitoring, please send me a short blurb to include here. Best would be with a sample URL and some hints about how you have configured MRTG ... For inspiration read the file mibhelp.txt If you want to watch your modem pool, there is help from Andreas Fuchs mrtg-modempool page

Frequently Asked Question with Answers

Q:The GIFs created by MRTG look very strange. Not all the grid lines are drawn and ...
A:Remove the *-{week,day,month,year}.gif files and start MRTG again. Using MRTG for the first time, you might have to do this twice. This will also help, when you introduce new routers into the cfg file.

Q: What is my Community Name?
A:Try 'public', as this is the default Community Name.

Q: I compiled your program and I get the following errors: at the command line I typed ./mrtg kirit.cfg and I get :

    Can't locate Socket.pm in @INC at /SNMP_Session.pm line 27. 
    BEGIN failed--compilation aborted at /SNMP_Session.pm line 27.
    BEGIN failed--compilation aborted at ./mrtg line 356.
A: You need to get Perl5 installed properly. Socket.pm comes with Perl5 and is an integral part of Perl5. Perl5 comes with compiled in defaults about where it should look for its libraries (eg Socket.pm). Type 'perl -V' to see what your perl assumes ... And get it fixed ... Eg by installing it properly.

MRTG Mailing List

There are two mailing lists for MRTG available. One is called 'mrtg' and is a discussion list for users and developers. The other is called 'mrtg-announce' and is a low volume list for MRTG related announcements.

To subscribe to these mailing lists, send a message with the subject line subscribe to either mrtg-request@list.ee.ethz.ch or mrtg-announce-request@list.ee.ethz.ch. For posting to the mrtg list use the address mrtg@list.ee.ethz.ch.

Further information about the usage of the mailing lists is available by sending a message with the subject line 'help' to either one of the request addresses.

For past activity there is also a mailing list archive available: http://www.ee.ethz.ch/~slist/mrtg

MRTG on Windows NT

By Stuart Schneider <SchneiS@testlab.orst.edu>

These are some basic notes on getting MRTG 2.0 running on a WindowsNT system (server or workstation versions of NT will work, as well as Win95 in most cases).

The prerequisites for running MRTG are:

  • Having TCP/IP installed and functioning correctly on your NT machine.
  • Having Perl for Win32 installed. Check the Perl for Win32 FAQ for more info.

The MRTG 2.0 port was tested using build 110 of the Win32 Perl 5 and with Service Pack 4 installed on a NT 3.51 server.

With the prerequisites taken care of, the hard part is compiling the rateup program as a Win32 character mode executable so that it can be called from Perl. A version compiled with Watcom C/C++ 10.6 and a statically linked GD library is available here.

The next step is to modify the MRTG script so that the $main::OS variable is set to 'NT'. At this point, create your mrtg.cfg configuration file and call 'perl C:\mrtg\mrtg c:\mrtg\mrtg.cfg' at regular intervals (there is a NT cron daemon that works well available from most of the SimTel mirrors).


If you have any questions about this program, or have it up and running,
we would like to hear from you:

MRTG
2.1-1997/04/24 Tobias Oetiker <oetiker@ee.ethz.ch> and Dave Rand <dlr@bungi.com>