| ]

MRTG is the most popular open source performance measuring tool being used around the world today. While MRTG is open source, it has been widely adopted by major companies everywhere who use it to measure network performance and adherence to SLAs, among other things. For an interesting snapshot of who is using MRTG, and for what purpose, go to MRTG's "Where, What, How" page and have a look at some of the interesting things MRTG is being used to track. Although MRTG started out as an application to measure network performance on routers (MRTG stands for "Multi Router Traffic Grapher"), it is being used today to graph everything from traffic jams in the Netherlands to the local temperature in Wroclaw. If you can provide a numeric value to MRTG, it can produce a graph of it.

This article is going to take you step by step into installing a fully-functional MRTG system, and give you some pointers on where to go from there. We are going to take advantage of some handy shortcuts, for the sake of time. Some of the steps may seem a bit weird initially, but this is the quickest and easiest way to get up and running. And that is the point of this exercise.

We will be relying on a number of pre-compiled packages to get us up and running. You should go fetch them now and have them available when we need them:

  • Active State's Active PERL
  • Open Innovation's MRTG Bundle

  • I opted to use MRTG Bundle for a number of reasons:

  • It comes with RRDTool, the defacto standard for performance-minded MRTG installations
  • It uses Routers2.cgi for the web front-end, which is generally preferred over the default 14all.cgi.
  • It comes with a small installation of Apache, so you don't have to reduce the security of your IIS server in order to view MRTG's output. This Apache installation runs on Port 9191, so it will not interfere with any IIS installation already running (unless IIS is also running on port 9191, which would be unusual)
  • Includes GetIF, which is a very handy SNMP utility that we will use later to determine the appropriate OID to use within MRTG.
  • It comes with a number of very useful scripts for managing new devices (though we will enhance these slightly)
  • It comes with UNIX-like Cron, which is much more reliable than Windows' built-in scheduler service when it comes to running tasks once a minute.
  • It's dead easy to install
  • While MRTG also includes a set of PERL binaries, there are a couple things included in Active State's full PERL that we will be relying on in some of the more advanced tasks later on.

    So, let's get started:

    1.Make sure the system you will be running MRTG on has SNMP enabled. Set the Read community to something obscure, and not easily guessed. For the purposes of this demonstration, I will use the default "public" for the Read Community. You should use something more complicated. You should also ensure that remote systems cannot query your SNMP service for information unless you explicitly allow. These are all properties of the SNMP Service's property page, Security tab. Screen shot is available here.

    2. Install Active PERL, taking the defaults. Reboot after installation.

    3. Execute the MRTG Bundle installation package that you downloaded from Open Innovations.

    4. Read and accept the GNU public license.

    5. DO NOT accept the default installation location. If you read the instructions on the page, you will notice they want you to install to "C:". Enter "C:" in the text box where "c:mrtg" is suggested.

    6. Once the installation directory is correctly set to "c:", hit Install and observe the files being placed in the appropriate directories. This will take some time, there are a lot of files.

    7. Once finished, you should be left with an MRTG directory on your C drive.

    8. If you have a list of routers or other network devices that you want to have auto-detected for you, edit the c:\mrtg\mrtg\bin\myrouters.txt file. Put each device on a separate line, using the format communitystring@IPAddress.

    For instance, if you have a router at 10.0.0.1, with a community string of "public", you would put public@10.0.0.1 in the myrouters.txt file.

    The initial entry (communitystring@ipaddressofserver) is there just for instructional purposes and should be replaced with a real entry. Entries in this file will be scanned during the next step of the installation, and an MRTG config file will be automatically generated during the next step of the installation. This is particularly handy with switches, where the large number of ports are tedious to configure manually within an MRTG config file. For the purposes of this demonstration, I am listing 2 of my Cisco switches, which are configured for the default "public" SNMP community. My myrouters.txt file can be viewed here.

    9. Once your myrouters.txt file is complete and saved, open a command prompt and navigate to the c:mrtg directory

    10. In c:\mrtg, execute the "install.bat" file.

    11. Hit ENTER after reading the introduction screen. Note the warning that all input must be given in LOWER CASE during this installation process.

    12. Answer "y" to the question about installing SNMP4W2K on the local machine (you can say no to this, but it gives you a good starting point on making config files for Windows servers), then hit ENTER.

    13. Enter a 1 or 2 when asked how many CPUs the local computer has, then hit ENTER.

    14. A new command window will launch, starting the installation of SNMP4W2K. Follow the prompts to complete that installation.

    15. When the SNMP4W2K install is complete, the command window will close, and a Readme file is displayed. You can safely close that, or read it. Your call.

    16. Notice our original command window has been patiently waiting for us to tell it that SNMP4W2K has finished installing.

    17. Hit ENTER in the original command window to proceed with the MRTG installation

    18. It will prompt you about the MyRouters.txt file. Enter "y" here if you have configured one as I instructed in Step 8, otherwise enter "n" and hit return to proceed.

    19. Verify the installation options, enter "y" and hit ENTER to proceed with the installation.

    20. The installation script will proceed to build your initial set of config files, querying the devices you specified in the myrouters.txt file for various interface information. It will then start the necessary services (Apache and Cron), and installation is complete

    21. Open your favorite web browser, and point it to http://localhost:9191. You should be presented with a screen that resembles this.

    22. Congratulations! MRTG is installed. You've earned a Fat Tire.

    Upgrading MRTG:
    Before you go much further, you will want to upgrade to the latest version of Routers2.cgi and RRDTool:

    Upgrading Routers2.cgi:

    1. Go to Routers2.cgi's home page and download the latest version of Routers2.cgi. Note that the current release version has a security flaw, so we will be using one of the Beta versions, v2.14-beta7. These versions roll often, so the link to Beta7 may be old by the time you read this. Use whatever the latest version is.

    2. Unzip the files to your c:\MRTG directory (it will create a directory called routers2-v2.14 as a result)

    3. Open a command window and navigate to the c:\mrtg\routers2-v2.14 directory

    4. Execute the following: perl install.pl (note the following instructions may become inaccurate as future Routers2.cgi versions are released)

    5. Hit Enter to continue past the introduction screen

    6. You may receive warnings of various libraries not being installed. If you have installed the latest version of Active Perl, as I suggested, it is safe to ignore these warnings.

    7. When it asks what drives to check, accept the default of "C" and hit ENTER

    8. When it asks where you web root is, DO NOT ACCEPT THE DEFAULT. In most cases, the default will be c:inetpubwwwroot, which is incorrect. Our installation has put our web files in c:\mrtg\wwwroot. So type that in and hit ENTER.

    9. Enter the same thing for the question about where the CGI files are kept: "c:\mrtg\wwwroot" and hit ENTER

    10. The next question is about the location of the MRTG config files. Enter "c:\mrtg\mrtg\bin" and hit ENTER

    11. The next question is about the names of the config files themselves, it is safe to just hit ENTER on this question, taking the default of "*.cfg"

    12. Next it wants to know where the RRD database files are being held. It defaults to c:\mrtg\wwwroot, which is correct. Just hit ENTER.

    13. Next it wants to know where your perl.exe file is located. It will default to c:\mrtg\perl\bin\perl.exe. Accept the default and hit ENTER

    14. Next it asks where your routers2.conf file is located. Although it warns you not to change the default without a good reason, ours is located in c:\mrtg\mrtg\bin\routers2.conf. Enter that in and hit ENTER.

    15. Accept the defaults for the next series of questions ("Activate Routing Table Extensions?", "How big should K be?", "Do you want to use authentication?" and "Can I email the author?"). Feel free to say YES to the emailing question, if you have ready access to a mail server.

    16. Then you will be presented with a summary of the options we have just set, and asked if it's OK to proceed with the installation. Hit ENTER to proceed unless you have made a mistake somewhere along the line.

    17. When asked if you want to overwrite routers2.conf, say "yes" and hit ENTER

    18. Hit Enter again at the "All Done?" prompt

    19. Copy mrtg\wwwroot\index.cgi c:\mrtg\wwwroot\index_cgi.bak

    20. Copy mrtg\wwwroot\routers2.cgi c:\mrtg\wwwroot\index.cgi

    21. Run "net stop apache", then "net start apache" to restart the web server.

    22. You're all done with upgrading Routers2.cgi. Have another Fat Tire.

    Upgrading RRDTool:
    1. Go to the RRDTool distribution page and download the latest Win32 binaries (currently v1.0.48)

    2. Unzip them into c:mrtgrrdtoolupdate

    3. Open a command prompt and navigate to c:mrtgrrdtoolupdatesrc

    4. Copy the .exe files from each of the 4 "*_release" directories (tool_release, stats_release, rrd_cgi_release, and bounds_release) to c:\mrtg\rrdtool, overwriting the files that were originally in that directory.

    5. You're done. What the hell, have another Fat Tire!

    Tweaking Routers2.conf:
    When we upgraded to the latest version of Routers2.cgi, we lost a couple things that we want to get back. One of them was the 6-hour graph, which is now disabled by default. Also, the scale of the graphs is wacky, and shows the maximum possible values at the top, instead of scaling smartly based on the data coming in. This makes for much less useful graphs, especially in environments where the traffic levels are such that they don't even seem to register properly on the graphs.

    So, open c:\mrtg\mrtg\bin\routers2.conf in your favorite test editor (TextPad is mine), and make the following changes:

  • Change the line #unscaled = no to unscaled = no, removing the comment tag "#"
  • Change the line #6hour = no to 6hour = yes, removing the comment tag and changing the value to yes
  • If you want 95th Percentile calculations that show the 95% average value over the course of a given graph, remove the # in front of the line #percentile = yes. This can consume a lot of your system's CPU time on a machine monitoring a lot of devices, so don't enable it in environments where you expect the MRTG machine to be working hard already.
  • Uncomment #windowtitle and #pagetitle directives, and set them to something appropriate for your environment. This will change the default page heading from "Router Monitor" to whatever you enter here.
  • Uncomment #withdate = yes to show the dates on the graphs when they were last generated. This is useful for troubleshooting an MRTG problem.
  • Close your editor, saving changes. The changes will be reflected the next time you refresh your web page.
  • Adding Devices to MRTG:
    Adding devices to MRTG is a 2-step process. First, a new .cfg file must be created for the new device. Then Cron must be configured to regularly poll the device for the graph data. Remember, Cron is the facility we are using to query the devices every minute for metrics.

    In the c:\mrtg directory, you will notice a number of handy batch files left behind by the Open Innovations bundle we initially used to install MRTG:

  • Update_MyRouters.bat: This batch file will process the c:\mrtg\mrtg\bin\myrouters.txt file as if they were there during the original installation. A basic cfg file will be built for the device automatically.
  • Manually-run-mrtg.bat: This batch file will run the MRTG process on the localhost.cfg file that was created during installation. This is the exact command that Cron runs every minute on each of your MRTG targets to fetch data for the graphs.
  • While these batch files are helpful, I found it easier to modify them slightly for my own use:

  • In the manually-run-mrtg.bat file, I replaced "localhost" with "%1", which allows me to run the batch file with any cfg file I specify on the command line. I also renamed it to something shorter, for usability reasons. It is now called "UpdateMe.bat", and you can view it here. I execute it by running Updateme.bat . For instance, if I was making some tweaks to the 10.0.0.252.cfg file, and I didn't want to wait for Cron to get around to updating things, I would just execute updateme.bat 10.0.0.252 and the graphs would be updated immediately in MRTG.
  • I wanted an easy way to add a new device to MRTG without having to go through the myrouters.txt thing. I have enough devices around now that I can usually use an existing cfg file for the new device, instead of having to go through the whole process of generating a fresh cfg using Update_MyRouter.bat. So I made a shortcut batch file for that too, called NewCFG.bat. You can see it here. You must specify the name of the cfg file (without the .cfg extension) at runtime. For instance, if you had a new cfg file called "NewDevice.cfg", you would run NewCFG.bat NewDevice and it would run the initial MRTG and add the device to the crontab.
  • Routers.cgi Directives in the device.cfg Files:
    I've shown you how your can customize MRTG's display by diving into the Routers2.conf file. If you look through the file, you will see there are many options you can tweak with, and it is fairly well documented.

    However, I prefer to use the cfg files for the individual devices to make the majority of my tweaks. And with the latest version of Routers2.cgi, it's terribly easy to do so.

    Let's say we want to change the default icon for my Cisco 2916 switch at 10.0.0.252. There are a bunch of icons already made for you in the c:\mrtg\rrdtool\rrdicons directory. I want to change the icons for my Cisco device to a small Cisco icon, which is made available as "cisco-sm.ico" in the rrdicons directory. I also want to change the menu from displaying "10.0.0.252" to something more friendly, like "2916M-XL". Here's how it's done:

    1. With your favorite text editor, open the device's cfg file, in this case it's c:\mrtg\mrtg\bin\10.0.0.252.cfg

    2. In the section towards the top, where the Global Defaults are set, add a line that says routers.cgi*Icon: cisco-sm.gif

    3. Add another line that says routers.cgi*ShortDesc: 2916M-XL

    4. Save the file.

    The next time your web site is refreshed, it should reflect the changes.

    A full list of Routers.cgi directives, and what each does, can be found here.

    Conclusion:

    I hope I've given you enough information here to get started with MRTG on Windows, and some insight into the potential of the system. Follow-up articles will go into more detail about the configuration options available within the cfg files, as well as how to use WMI and Performance Monitor to query Windows systems for more advanced metrics.

    If you notice any errors on this document, or have questions or feedback, please feel free to contact me at beaumonday@qwest.net

    Beau Monday has been in the computer industry for 17 years and holds a myriad of certifications from Microsoft, Cisco, Checkpoint, Nokia, SANS, and others. Beau specializes in monitoring and securing Microsoft-based networks, and he's currently the Security Officer at SumTotal Systems in Seattle, where he makes his home with his wife and 2 cats. More of Beau's security articles can be seen at his weblog (http://bmonday.com)