Using MRTG with Linksy Routers

How to setup MRTG to graph statistics from Linksys routers


#####Props to Mathew Atkins who did the orginal write up and collector.pl script. I just edited it to suit my needs.#####
http://www.akins.org/matthew/linksys.html

Requirements


Procedures

Installation

  • Install NetSNMP.
  • Install MRTG.
  • Copy the Perl Scriptcollector.pl to /usr/local/bin/collector.pl and chmod 755

Configuration

  • Enable SNMP Logging in the router by navigating to the Log Section and placing
    the IP address of your Linux server as the logging destitation.
  • Edit /etc/snmp/snmptrapd.conf and place the following entry: NOTE: You may need to create this file
    traphandle default /usr/local/bin/collector.pl
    
  • Edit your mrtg.cfg with the following entry to monitor Traffic on the Router
    #################################
    #       GLOBAL                  #
    #################################
    
    WorkDir: /var/www/html/mrtg
    
    #################################
    #  Linksys Roouter              #
    #################################
    WriteExpires: Yes
    Title[^]: Traffic Analysis for
    Title[router]: Linksys Router
    PageTop[router]:Linksys Firewall/Router
    Target[router]: `cat /tmp/router.out`
    MaxBytes[router]: 187000
    

Configuration Test

  • To ensure that your server is recieving the traps, run
    snmptrapd -d -O T
    
    
    Now, from a machine behind the router, surf the web
    for a bit to generate some packet logs.
    cat /var/log/syslog and you should see lots of info regarding web traffic
    being logged from the router.
  • cat /tmp/router.out
    And you should see the following output that should cahnge whenever a trap is received.
    1352664
    539539171
    0:5:17:56.71
    router
    
  • Run mrtg against your mrtg.cfg file
    /usr/local/mrtg-2/bin/mrtg /var/www/html/mrtg/mrtg.cfg
    
    You should see various file appearing in the working directory of your mrtg configuration file.
    You will get errors the first couple of times running mrtg but this is normal.
    If you are still getting errors after the fourth time, something is wrong and you should
    double check your configuration.

Finishing touches

  • Start the snptrapd daemon and set it so it starts on boot.
    I use the following bash script in /etc/init.d and is called by rc*.d files
    #!/bin/bash /usr/sbin/snmptrapd -d -O T
  • Add mrtg to roots crontab so that it runs every five.
    Notice how mrtg logs to the mrtg.log file
    #Added for MRTG
    0,5,10,15,20,25,30,35,40,45,50,55 * * * *  /usr/local/mrtg-2/bin/mrtg 
    /var/www/html/mrtg/mrtg.cfg --logging /var/log/mrtg.log #1>/dev/null 2>/dev/null
  • Now you should be able to browse to your server and see the MRTG graphs.
    With a little web surfing, you should see some results in 10 to 15 minutes.

  • MRTG Graphs for Linksys Cable/DSL Router