MRTG  Mini  How-To
Author:  Ruwan Jayasinghe <rjayasin**lausd.k12.ca.us>
Contributor: Darrell May, Placido Sanchez, and Dan York.
Release supported: RH73
License: GPL
Last updated: October 9, 2003
RJ
Problem:  You want to monitor traffic patterns of individual ports on Cisco Switches/Routers on your network.

Solution:  By installing the *MRTG RPM* and following the procedure here, you will wind up with a directory that graphically displays traffic statistics such as, input/output per switch port in bps sampled/averaged every 5mins and graphed, hourly, daily, weekly and yearly for each of your Cisco switches and routers.  For more information about MRTG or to see examples of the output, visit the MRTG Home Page. This may work on other "manageable" switches/routers if they support SNMP.  An example graph of weekday traffic:

STEP 1:  Download and install the rpm
Download MRTG RPM Here

Or
[root@localhost]# wget ftp://rpmfind.net/linux/7/redhat/7.3/en/os/i386/RedHat/RPMS/mrtg-2.9.17-3.i386.rpm

Then install rpm by,
[root@localhost]# rpm -ivh mrtg-2.9.17-3.i386.rpm

Or with a recent version of RPM, download and install simultaneously using,
[root@localhost]# rpm -vhU ftp://rpmfind.net/linux/7/redhat/7.3/en/os/i386/RedHat/RPMS/mrtg-2.9.17-3.i386.rpm

STEP 2:  create a directory in /var/www/html named "mrtg" 
(cgi permissions not needed, just read access )

[root@localhost]# mkdir -p /var/www/html/mrtg

STEP 3:  copy/paste the shell script below, name it "create-mrtg" and save in /root. Or get from here.

#!/bin/bash
#This script will create a folder inside the directory /var/www/html/mrtg" which is named 
#by the first argument. It will create a cfg file inside the /etc/mrtg folder. It will also add 
#a line to the script "/etc/mrtg/all-ip" so that crontab will run this script which in turn will 
#run mrtg for each device. The second argument is the IP address of each device to be 
#monitored..This script is best run when "all" the workstations connected to it are powered 
#up because "cfgmaker" ignores inactive ports when it is run.
#       EX:
#                                                    Arg1     Arg2
#                                                       |         | 
#[root@localhost /root]# create-mrtg 10001 10.0.0.1
# Create a "workdir" for this device using the first variable
mkdir -p /var/www/html/mrtg/$1

#create the cfg file for this Ip address using the first variable (assumes community string is "public")
perl /usr/bin/cfgmaker public@$2 --global "workdir: /var/www/html/mrtg/$$1" --output /etc/mrtg/$1.cfg

#Create an index.html file for this folder using the first variable
perl /usr/bin/indexmaker /etc/mrtg/$1.cfg > /var/www/html/mrtg/$1/index.html

#create an entry in script "all-ip" to run mrtg for each device. 
echo "/usr/bin/mrtg /etc/mrtg/$1.cfg;" >> /etc/mrtg/all-ip 

#Uncommenting the line below will create a "master" index.html inside the /var/www/html 
#directory for all devices. Note that this line will create a text file called index.html. 
#It should be edited for correct html syntax.

#echo "<br><a href=$1/index.html> MRTG of Device $1 </a>" >> /var/www/html/mrtg/index.html
 

STEP 4:  Make the create-mrtg script executable by,

           [root@localhost]# chmod 755 create-mrtg

STEP 5:  Now run create-mrtg
                                                                      Arg1      Arg2
                                                                         |           |
      EX:   [root@localhost /root]# ./create-mrtg IDF1SW1 10.0.0.1
  • Where "IDF1SW1" is the first argument and is used to create,
    • the mrtg configuration file for this device 
      • EX: "/etc/mrtg/IDF1SW1.cfg",
    • a directory to place the png and html files created when the script runs
      • EX: "/var/www/html/mrtg/IDF1SW1"
  • And "10.0.0.1" is the ip address of the device. 
  • STEP 6: Now run these commands once from the root prompt,

     [root@localhost /root]# chmod 755 /etc/mrtg/all-ip

     [root@localhost /root]# echo "0-59/5 * * * * root /etc/mrtg/all-ip" >> /etc/crontab
     

    STEP 7:  Now wait a few minutes (20 or so) and try
    EX:  http://your.server.ip/mrtg/IDF1SW1
    Notes:
    1. If you don't know all the IP addresses of your devices, you will find a freeware Win32 utility called Checkip 1.2 here. This will scan all known IPs in a given subnet.
    2. If you use the E-Smith/Mitel SME Server, here are more specific instructions.. 
    3. Remember to maximize the browser window before selecting/copying the the script above. Doing that will avoid lines from wrapping around and causing problems. 
    4. If you are using a Windows client to access the prompt, It is very easy to copy/paste into a shell window. Just open a new edit session with pico, select/copy all the "small" text below, then "right-click" inside the shell/pico window to paste, then CTRL-X, Y, to save. This works when using the command line too.
    5. Checkout the MRTG site for other options available for the "indexmaker"  and  "cfgmaker" that would allow you to customize the presentation of the charts.

    See who's visiting this page. View Page Stats
    See who's visiting this page.