MRTG to monitor Cisco Routers, the quick way

MRTG (The Multi Router Traffic Grapher) is a very cool application. It runs on Linux, OS X and also under Windows (with Perl support) and it can draw graphs about everything (everything that support SNMP). I use this piece of software to monitor network interfaces and of course routers.
With Cisco routers you need to enable the SNMP support under the CLI. So, after the telnet connection, become “superuser” (the enable command) and create the SNMP community:

router# enable
router# configure terminal
router(config)# snmp-server community CommunityName RO
router(config)# exit
router#

PS: if you get MRTG working, you can run also the command wr memory to save the router config so you can reboot the device without loosing settings:

router# wr memory

Now, under your Linux system (on the others systems these steps may be similar…) you need only to install with your favorite package manager the MRTG package. After becoming root as usual (with su or sudo -s) run this command (create before the dir /var/www/html/mrtg and /etc/mrtg):

linux@host# cfgmaker –global ‘WorkDir: /var/www/html/mrtg’ \
–output /etc/mrtg/mrtg.cfg CommunityName@192.168.0.254

You can now run the mrtg program with the config file as option:

linux@host# mrtg /etc/mrtg/mrtg.cfg

Now your router traffic will be graphed! (check http://your_linux_server/mrtg/)
Is a good idea to create a cron job to update the graph every five minutes. Create a file into /etc/cron.d named mrtg.cron with this content:

0-59/5 * * * * root /usr/bin/mrtg /etc/mrtg/mrtg.cfg

PS: Into this little tutorial I suppose the presence of a running Linux server with apache installed and a Cisco router with the private address 192.168.0.254. Also all programs path may change due to your system/distro…
I don’t cover all possible security improvements (like protect your router from Internet, setting htaccess password to your web server, etc…). But remember always to check twice all your potential security issues.

12 Responses to “MRTG to monitor Cisco Routers, the quick way”

  1. Dex Says:

    I followed your tutorial and get this :

    # /usr/bin/cfgmaker –global ‘WorkDir:/srv/www/htdocs/mrtg’ –output /etc/mrtg/mrtg.cfg ro@222.224.28.8

    –base: Get Device Info on ro@222.224.28.8:
    SNMP Error:
    no response received
    SNMPv1_Session (remote host: “222.224.28.8″ [222.224.28.8].161)
    community: “ro”
    request ID: -221942610
    PDU bufsize: 8000 bytes
    timeout: 2s
    retries: 5
    backoff: 1)
    at /usr/bin/../lib/mrtg2/SNMP_util.pm line 627
    SNMPWALK Problem for 1.3.6.1.2.1.1 on ro@222.224.28.8::::::v4only
    at /usr/bin/cfgmaker line 796
    WARNING: Skipping ro@222.224.28.8: as no info could be retrieved

    –base: Writing /etc/mrtg/mrtg.cfg

    What is the problem here, help please.
    Thanks.

  2. Paolo Says:

    Hi Dex,
    your IP 222.224.28.8 seems to be a public address. Usually SNMP on router CISCO can be easily reached from the INSIDE interface and not from outside. To allow the SNMP query from Internet, you need to setup some ACL on your router console on trusted IP.

  3. GR Seshagiri Says:

    Hi Paolo,

    Your site was of immense help to me to get the MRTG working. Thank you so much for your detailed instructions.

    –seshagiri

  4. George Mason Says:

    Great tutorial, helped me out no end - why couldn’t everyone else put it so simply! Thanks very much.

    George

  5. Rauf Says:

    I must appreciate your compact and concise tutorial which helped me out. If u could plz mention some thing about ‘how to view the graphs in windows environment. Thanx

  6. Bassam Says:

    i need to know how to monitor cisco routers memory and cpu by MRTG

  7. Rich Says:

    Ok that was far too simple. I’ve spent an hour reading over Cisco SNMP specifications and trying to work out how I can graph our WAN link, and which of the million or so (or so it seems) MIB values will output what I need.

    After reading your very brief howto, and running cfgmaker it’s all working perfectly within a couple of minutes!

    Brilliant! Thank you so much!

  8. Arsenic Says:

    Thank’s for your howto, it helped me to monitor my wan link, and i am very happy because before that i have spent lot of time to search what was the source of the errors in my config command line !

  9. Talile Says:

    Your site is of great help but when I enter:
    cfgmaker –global “workDir: /home/tmiresa/public_html/mrtg” –output /home/tmiresa/mrtg/mrtg.cfg ro@10.140.67.3

    This error:

    Error:
    can’t resolve ” ro@10.140.67.3″to IP address
    at /usr/share/perl5/SNMP_util.pm line 426
    SNMPWALK Problem for publicro@10.140.67.3::::::v4only
    at /usr/bin/cfgmaker line 921
    WARNING: Skipping publicro@10.140.67.3: as no info could be retrieved

    What is the problem here, help please.
    Thanks in advance!

  10. Paolo Says:

    Hi Talile,
    have you tried to install SNMP/SNMPWALK in your server (the machine with cfgmaker)?

  11. Evelyne Schweigart Says:

    Good site i love it

  12. Nick Potts Says:

    Paolo thanks so much for this keep them coming, Nick

Leave a Reply