Sunday, May 8, 2016

simple and easy way to graph cisco network traffic

*** setup infomation ***
server: ip 192.168.202.25
cisco: ip 192.168.202.23
          snmp community string: test
          snmp version: v2
          interface to graph: f2/0

*** cisco router configuration ***
1- enable snmp-server and allow 192.168.202.25 for read only, so on configure terminal mode type the following command
snmp-server community test RO
snmp-server host 192.168.202.25 informs version 2c test
snmp-server host 192.168.202.25 version 2c test 


2- the following is the whole running-config of the router
R1#show running-config
Building configuration...

Current configuration : 1081 bytes
!
version 15.2
service timestamps debug datetime msec
service timestamps log datetime msec
!
hostname R1
!
boot-start-marker
boot-end-marker
!
!
no aaa new-model
no ip icmp rate-limit unreachable
ip cef
!

!
no ip domain lookup
no ipv6 cef
!        
!        
multilink bundle-name authenticated    
!        
!        
ip tcp synwait-time 5
!        
!        
interface Loopback0
 ip address 192.168.245.245 255.255.255.0
!        
interface FastEthernet0/0
 no ip address
 shutdown
 duplex full
!        
interface FastEthernet2/0
 ip address 192.168.202.23 255.255.255.0
 speed auto
 duplex auto
!        
interface FastEthernet2/1
 no ip address
 shutdown
 speed auto
 duplex auto
!        
ip forward-protocol nd
!        
!        
no ip http server
no ip http secure-server
!        
!        
snmp-server community test RO
snmp-server host 192.168.202.25 informs version 2c test
snmp-server host 192.168.202.25 version 2c test
!        
!        
control-plane
!        
!        
line con 0
 exec-timeout 0 0
 privilege level 15
 logging synchronous
 stopbits 1
line aux 0
 exec-timeout 0 0
 privilege level 15
 logging synchronous
 stopbits 1
line vty 0 4
 login   
!        
!        
end      

         

*** mrtg server ***
1- install mrtg on the server
$ sudo apt-get install mrtg

2- generate mrgt configuration for graphing traffic of cisco interface f2/0,
$ sudo cfgmaker test@192.168.202.23 --ifref=f2/0 > /etc/mrtg.cfg
-if you need to graph more interface, do not use redirect like above it will override the old configuration. so you can generate but add manually tto /etc/mrtg.cfg from the output of the command.

3- if you setup router correctly you will see the content of /etc/mrtg.cfg like below
WorkDir: /var/www/mrtg
EnableIPv6: no
Target[192.168.202.23_Fa2_0]: #Fa2/0:test@192.168.202.23:
SetEnv[192.168.202.23_Fa2_0]: MRTG_INT_IP="192.168.202.23" MRTG_INT_DESCR="FastEthernet2/0"
MaxBytes[192.168.202.23_Fa2_0]: 12500000
Title[192.168.202.23_Fa2_0]: Traffic Analysis for Fa2/0 -- R1
PageTop[192.168.202.23_Fa2_0]: <h1>Traffic Analysis for Fa2/0 -- R1</h1>
        <div id="sysdetails">
            <table>
                <tr>
                    <td>System:</td>
                    <td>R1 in </td>
                </tr>
                <tr>
                    <td>Maintainer:</td>
                    <td></td>
                </tr>
                <tr>
                    <td>Description:</td>
                    <td>FastEthernet2/0  </td>
                </tr>
                <tr>
                    <td>ifType:</td>
                    <td>ethernetCsmacd (6)</td>
                </tr>
                <tr>
                    <td>ifName:</td>
                    <td>Fa2/0</td>
                </tr>
                <tr>
                    <td>Max Speed:</td>
                    <td>12.5 MBytes/s</td>
                </tr>
                <tr>
                    <td>Ip:</td>
                    <td>192.168.202.23 (No DNS name)</td>
                </tr>
            </table>
        </div>

4- create mrtg working direction
$ sudo mkdir -p /var/www/mrtg

5- create cron job to query snmp data from router every 5 minute. check if there is a file, /etc/cron.d/mrtg and have the following content
*/5 *    * * *    root    if [ -x /usr/bin/mrtg ] && [ -r /etc/mrtg.cfg ] && [ -d "$(grep '^[[:space:]]*[^#]*[[:space:]]*WorkDir' /etc/mrtg.cfg | awk '{ print $NF }')" ]; then mkdir -p /var/log/mrtg ; env LANG=C /usr/bin/mrtg /etc/mrtg.cfg 2>&1 | tee -a /var/log/mrtg/mrtg.log ; fi
- restart cron to make the modification take affect
$ sudo /etc/init.d/cron restart
6- now if you are lazy to continue and your server support X or x forwarding, you can view the graph by using firefox to view html file in /var/www/mrtg/
$ firefox  /var/www/mrtg/192.168.202.23_fa2_0.html 



7- or you can configure on apache2 to be able to access by and pc, by create file /etc/apache2/conf-enabled/mrgt.conf with following content
Alias /mrtg/ /var/www/mrtg/
<Directory /var/www/auth/>
    Options +FollowSymLinks +Indexes
</Directory>


- restart apache2 to make the modification take affect
$ sudo /etc/init.d/apache2 restart
 
then the url to access is http://server-ip/mrtg/192.168.202.23_fa2_0.html

No comments:

Post a Comment