mrtg-2.12.2-2 (Monitoring)

Updated on 18 Jan, 2006 by SuSE 10.0

Multi Router Traffic Grapher

SNMP

  • Make sure net-snmp is installed, configured, and running.
  • On Linux, net-snmp-5.2.1-10.i586.rpm is installed, and configuration would look like this (etc/snmp.conf).
    #
    # First, map the community name "public" into a "security name"
    #	sec.name source	community
    com2sec	public	default	public
    
    # Second, map the security name into a group name.
    #	groupName	securityModel	securityName
    group	public		v1		public
    group	public		v2c		public
    group	public		usm		public
    
    # Third, create a view for us to let the group have rights to:
    #	name	incl/excl	subtree	mask(optional)
    view	all	included	.1
    
    # Finally, grant the group read-only access to the systemview view.
    #	group	context	sec.model	  sec.level prefix	read	write	notif
    access	public	""	any		noauth	exact	all	all	all
    
    # System contact information
    #
    syslocation	xxxxxxxx
    syscontact	foo@host
    
  • On Windows 2000, XP, 2003, SNMP Service should be installed, and it would look like this,
  • On CISCO products, SNMP configuration would like like this,
    gw(config)#snmp-server community public RO
    
  • Make sure, snmp is running and accessible. If necessary, open 161 tcp, udp ports on the target device.
    # snmpwalk -v 1 192.168.1.100 -c public | less
    SNMPv2-MIB::sysDescr.0 = STRING: Hardware: x86 Family 6 Model 9 Stepping 5 AT/AT CO
    MPATIBLE - Software: Windows 2000 Version 5.1 (Build 2600 Uniprocessor Free)
    SNMPv2-MIB::sysObjectID.0 = OID: SNMPv2-SMI::enterprises.311.1.1.3.1.1
    DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (80732) 0:1
    SNMPv2-MIB::sysContact.0 = STRING:
    SNMPv2-MIB::sysName.0 = STRING: TS-NEC
    SNMPv2-MIB::sysLocation.0 = STRING:
    SNMPv2-MIB::sysServices.0 = INTEGER: 76
    IF-MIB::ifNumber.0 = INTEGER: 4
    ....
    

    Installation

  • Install from SuSE installation source
    # rpm -ihv mrtg-2.12.2-2.i586.rpm
    

    Configuration

    The next step is now to configure mrtg for monitoring an network device.
  • Make sure net-snmp is installed, configured, and running.
  • Make mrtg directory
    # mkdir /srv/www/htdocs/mrtg
    
  • Make configuration file and run it (/etc/mrtg/makecfg.sh)
    #!/bin/bash
    
    # host list
    HOSTLIST="
    192.168.0.1
    192.168.0.2
    "
    
    # Make configuration file
    for HOST in $HOSTLIST
    do
            /usr/bin/cfgmaker \
                    --ifref=eth \
                    --global 'WorkDir: /srv/www/htdocs/mrtg' \
                    --global 'Options[_]: bits,growright' \
                    --output /etc/mrtg/$HOST.cfg \
                    public@$HOST
    done
    
    This example monitor two devices (192.168.0.1, 192.168.0.2) and makes two configuration files (192.168.0.1.cfg and 192.168.0.2.cfg)

    Run

  • Make an executing file (/etc/mrtg/mrtg.cron) to run
    #!/bin/bash
    
    DIRCFG=/etc/mrtg
    DIRHTML=/srv/www/htdocs/mrtg
    LISTCFG="
    192.168.0.1.cfg
    192.168.0.2.cfg
    "
    
    for CFG in $LISTCFG
    do
            env LANG=C /usr/bin/mrtg $DIRCFG/$CFG
    done
    
    # Make index file
    cd $DIRCFG
    /usr/bin/indexmaker --columns=1 $LISTCFG > $DIRHTML/index.html
    
  • To run every 5 minutes, add one line in /etc/crontab
    ...
    0-59/5 * * * * root /etc/mrtg/mrtg.cron >/dev/null 2>&1
    
  • In the default configuration, only the localhost can view the analysis from http://3/mrtg. However, if you want to allow other computer to view it, edit /etc/httpd/conf.d/mrtg.conf as below,
        Order deny,allow
    #    Deny from all
        Allow from localhost
        # Allow from .example.com
    

    Monitor CPU

    Add following lines to the configuration file.
    # This section creates CPU Load monitoring
    ### CPU Load Average ###
    Target[cpu_hostname]: .1.3.6.1.4.1.2021.10.1.5.1&.1.3.6.1.4.1.2021.10.1.5.2:public@localhost
    MaxBytes[cpu_hostname]: 100
    Unscaled[cpu_hostname]: dwmy
    Options[cpu_hostname]: gauge, absolute, growright, noinfo, nopercent
    YLegend[cpu_hostname]: CPU Load(%)
    ShortLegend[cpu_hostname]: (%)
    LegendI[cpu_hostname]: 1min ave
    LegendO[cpu_hostname]: 5min ave
    Legend1[cpu_hostname]: 1min ave(%)
    Legend2[cpu_hostname]: 5min ave(%)
    Title[cpu_hostname]: CPU Load ($HOST)
    PageTop[cpu_hostname]: <H1>CPU Load Average -- suse10</H1>
    

    Monitor Disk usage without snmp

  • Create a script at /usr/local/sbin/df.pl
    #!/usr/bin/perl
    
    # It assumes that the command output(df -kl) looks like this:
    # Filesystem           1k-blocks      Used Available Use% Mounted on
    # /dev/md0              95645100  30401312  64272080  33% /
    # /dev/hde1                14119      1159     12231   9% /boot
    #
    # In which case, this script returns :
    # 95659219
    # 30402503
    # when run.
    
    foreach $filesystem (`df -kl | grep -v "Filesystem"`)
    {
      @df = split(/\s+/,$filesystem);
      $total += $df[1];
      $usage += $df[2];
    }
    print "$usage\n";
    print "$usage\n";
    print "$total\n";
    
  • Give permission.
    # chmod 755 df.pl
    
  • create xinetd file at /etc/xinet.d/df
    service df
    {
            socket_type     = stream
            protocol        = tcp
            wait            = no
            user            = nobody
            bind            = 127.0.0.1
            server          = /usr/local/sbin/df.pl
    }
    
  • Add a line to /etc/services
    df              9047/tcp                        # df
    
  • Restart xinet.d
    # /etc/init.d/xinetd restart
    
  • Test the configuration
    # /usr/bin/netcat localhost df
    3479420
    3479420
    9931728
    
  • Add followings to the MRTG configuration file
    # Disk usage monitoring
    Target[disk_hostname]: `/usr/bin/netcat localhost df`
    Title[disk_hostname]: Disk Usage -- suse10
    Unscaled[disk_hostname]: dwym
    MaxBytes[disk_hostname]: 9931728
    PageTop[disk_hostname]: <H1>Disk Usage -- suse10</H1>
    kmg[disk_hostname]: KB,MB,GB
    LegendI[disk_hostname]: Used Disk Space
    LegendO[disk_hostname]: Total Disk Space
    Legend1[disk_hostname]: Used Disk Space
    Legend2[disk_hostname]: Total Disk Space
    YLegend[disk_hostname]:  Megabytes
    ShortLegend[disk_hostname]:  
    Options[disk_hostname]: gauge, growright, noinfo
    
  • Monitor Memory usage without snmp

  • Make sure you have sysstat-5.0.6-6.i586.rpm installed
  • Create a script at /usr/local/sbin/memory.pl
    #!/usr/bin/perl
    
    foreach $_ (`/usr/bin/sar -r 1 2 | grep "Average"`)
    {
      ($average, $kbmemfree, $kbmemused, $memused, $kbmemshrd, $kbbuffers, $kbcached, $kbswpfree, $kbswpused, $swpused) = split(/\s+/);
      print $kbmemused - $kbbuffers . "\n";
      print $kbmemused . "\n";
      print $kbmemused + $kbmemfree . "\n";
    }
    
  • Give permission.
    # chmod 755 memory.pl
    
  • create xinetd file at /etc/xinet.d/memory
    service memory
    {
            socket_type     = stream
            protocol        = tcp
            wait            = no
            user            = nobody
            bind            = 127.0.0.1
            server          = /usr/local/sbin/memory.pl
    }
    
  • Add a line to /etc/services
    memory          9057/tcp                        # memory
    
  • Restart xinet.d
    # /etc/init.d/xinetd restart
    
  • Test the configuration
    # /usr/bin/netcat localhost memory
    203578
    308974
    312960
    
  • Add followings to the MRTG configuration file
    # Memory usage monitoring
    Target[memory_hostname]: `/usr/bin/netcat localhost memory`
    MaxBytes[memory_hostname]:  312960
    Unscaled[memory_hostname]:  dwym
    YLegend[memory_hostname]:  Memory Usage
    ShortLegend[memory_hostname]:  
    kmg[memory_hostname]:  kB,MB
    kilo[memory_hostname]:  1024
    LegendI[memory_hostname]:  App Data
    LegendO[memory_hostname]:  Memory Used
    Legend1[memory_hostname]:  App Data
    Legend2[memory_hostname]:  Memory Used
    Options[memory_hostname]: gauge, growright, noinfo
    Title[memory_hostname]: Memory Usage -- suse10
    PageTop[memory_hostname]: <H1>Memory Usage -- suse10</H1>
    

    Monitor Swap usage without snmp

  • Create a script at /usr/local/sbin/swap.pl
    #!/usr/bin/perl
    
    foreach $_ (`/usr/bin/sar -r 1 2 | grep "Average"`)
    {
      ($average, $kbmemfree, $kbmemused, $memused, $kbbuffers, $kbcached, $kbswpfree, $kbswpused, $swpused, $kbswpcad) = split(/\s+/);
      print $kbswpcad . "\n";
      print $kbswpused . "\n";
      print $kbswpused + $kbswpfree . "\n";
    }
    
  • Give permission.
    # chmod 755 swap.pl
    
  • create xinetd file at /etc/xinet.d/swap
    service swap
    {
            socket_type     = stream
            protocol        = tcp
            wait            = no
            user            = nobody
            bind            = 127.0.0.1
            server          = /usr/local/sbin/swap.pl
    }
    
  • Add a line to /etc/services
    swap            9058/tcp                        # swap
    
  • Restart xinet.d
    # /etc/init.d/xinetd restart
    
  • Test the configuration
    # /usr/bin/netcat localhost swap
    40
    3104
    706820
    
  • Add followings to the MRTG configuration file
    # Swap usage monitoring
    Target[swap_hostname]: `/usr/bin/netcat localhost swap`
    MaxBytes[swap_hostname]: 706820
    Unscaled[swap_hostname]: dwym
    YLegend[swap_hostname]: Swap In Use
    kmg[swap_hostname]:  kB,MB
    kilo[swap_hostname]:  1024
    LegendI[swap_hostname]:  Cached Swap
    LegendO[swap_hostname]:  Swap Used
    Legend1[swap_hostname]:  Cached Swap
    Legend2[swap_hostname]:  Swap Used
    Options[swap_hostname]: gauge, growright, noinfo
    ShortLegend[swap_hostname]: 
    Title[swap_hostname]: Swap Usage -- suse10
    PageTop[swap_hostname]: <H1>Swap Usage -- suse10</H1>
    
  • Monitor Network Availability (ping)

  • Install mtr package which comes with SuSE. mtr is a network diagnostic tool.
    # rpm -ihv mtr-0.69-4.i586.rpm
    
  • Create a script as, /usr/local/sbin/ping.pl
    #!/usr/bin/perl
    # Usage: perl.pl host
    
    @result = split(/\s+/,`/usr/sbin/mtr -r $ARGV[0] | tail -n 1`);
    if ($result[7] != 0) {
            print $result[7] / $result[8] * 100 . "\n";
            print 100-$result[3] . "\n";
    } else {
            print "0\n";
            print "0\n";
    }
    
  • Change the permission
    # chmod 755 ping.pl
    
  • Add following into the mrtg configuration file. This monitor www.hoge.com
    # Network Availability
    Target[ava_hoge]: `/usr/local/sbin/ping.pl www.hoge.com`
    MaxBytes[ava_hoge]: 100
    Unscaled[ava_hoge]: dwym
    YLegend[ava_hoge]: Availability
    ShortLegend[ava_hoge]: (%)
    LegendI[ava_hoge]:  Stability (best/worst)
    LegendO[ava_hoge]:  Availability
    Legend1[ava_hoge]:  Stability (best/worst)
    Legend2[ava_hoge]:  Availability
    Options[ava_hoge]: gauge, absolute, growright, noinfo, nopercent
    Title[ava_hoge]: Availability -- www.hoge.com
    PageTop[ava_hoge]: <H1>Availability -- www.hoge.com</H1>
    
  • This configuration checks connectivity for 10 seconds (ten pings on each second) on every five minues.
  • To monitor multiple destinations, repeat the configuration, but change the bold place.
    Back
    Google
    Web www.grape-info.com