Search:  
Gentoo Wiki

HOWTO_Use_MRTG_with_a_D-Link_Switch_without_SNMP


This article is part of the HOWTO series.
Installation Kernel & Hardware Networks Portage Software System X Server Gaming Non-x86 Emulators Misc

Introduction

The Multi Router Traffic Grapher (MRTG) is a tool to monitor the traffic load on network-links. MRTG generates HTML pages containing graphical images which provide a LIVE visual representation of this traffic. Check http://www.ee.ethz.ch/stats/mrtg/ for an example. MRTG is based on Perl and C and works under UNIX and Windows NT. MRTG is being successfully used on many sites around the net.

Some D-Link switches like the des-1250G do not have SNMP but they do have a web interface to view statistics on all the ports. Here you will see how to create a script that will log into the web interface, write the port statistics to a series of files for MRTG to read.

Dependencies

mrtg
curl
awk
perl

Configuration

Create a script to gather stats from the d-link web administration page. I call this script dl-switch01.sh and I call it from a mrtg master control file that is kicked off from the crontab every 5 minutes.

#!/bin/sh

/usr/local/bin/curl --silent -d "passwd=your_password&post_url=cgi_device." http://192.168.1.2/cgi_statist>/dev/null
# Where 192.168.1.2 is the IP or hostname of your switch
/usr/local/bin/curl --silent -d "passwd=your_password&post_url=cgi_statist." http://192.168.1.2/cgi_statist>/usr/local/www/mrtg/dl-switch01/source.txt

STATPATH="/usr/local/www/mrtg/dl-switch01"
SOURCE="/usr/local/www/mrtg/dl-switch01/source.txt"
COUNTER=0
while [ $COUNTER -le 8 ]
do
        COUNTER=`expr $COUNTER + 1`
awk ' / *<b>'0$COUNTER'$/ {getline;print;getline;print} ' $SOURCE|tr -d '<td>'>$STATPATH/0$COUNTER.val
# Switch counts packets so conversion is not needed.
#awk ' / *<b>'0$COUNTER'$/ {getline;print;getline;print} ' $SOURCE|tr -d ' <td>'|awk 'BEGIN {getline tx;print tx *=  8;getline rx;print rx *=  8;}'>$STATPATH/0$COUNTER.val
done

COUNTER=9
while [ $COUNTER -le 49 ]

do
        COUNTER=`expr $COUNTER + 1`
awk ' / *<b>'$COUNTER'$/ {getline;print;getline;print} ' $SOURCE|tr -d '<td>'>$STATPATH/$COUNTER.val
# Switch counts packets so conversion is not needed.
#awk ' / *<b>'$COUNTER'$/ {getline;print;getline;print} ' $SOURCE|tr -d ' <td>'|awk 'BEGIN {getline tx;print tx *=  8;getline rx;print rx *=  8;}'>$STATPATH/$COUNTER.val
done

# Log out of the Web interface
/usr/local/bin/curl --silent http://192.168.1.2/cgi_logout>/dev/null

/usr/local/bin/mrtg /usr/local/etc/mrtg/configs/dl-switch01.cfg

Here is an example of what your mrtg config file should look like.

Options[_]: growright,noinfo

#       Include dl-switch01.cfg

WorkDir: /usr/local/www/mrtg/dl-switch01

Target[dlswitch01-01]: `cat /usr/local/www/mrtg/dl-switch01/01.val`
MaxBytes[dlswitch01-01]: 10000000
YSize[dlswitch01-01]: 200
XSize[dlswitch01-01]: 400
YLegend[dlswitch01-01]: Packets per second
ShortLegend[dlswitch01-01]: Packets/s
Title[dlswitch01-01]: D-Link Switch01 Ethernet Port-01
PageTop[dlswitch01-01]: <H1>D-Link Switch01 Ethernet-Port 01
 </H1>
 <TABLE>
   <TR><TD>System:</TD><TD></TD></TR>
   <TR><TD>Maintainer:</TD><TD></TD></TR>
   <TR><TD>Interface:</TD><TD>dl-switch01 port-01</TD></TR>
   <TR><TD>IP:</TD><TD></TD></TR>
   <TR><TD>Max Speed:</TD>
       <TD>100.0 Mbits/s (ethernetCsmacd)</TD></TR>
  </TABLE>

You will want to repeat that portion upto port 50.

Retrieved from "http://www.gentoo-wiki.info/HOWTO_Use_MRTG_with_a_D-Link_Switch_without_SNMP"

Last modified: Fri, 07 Dec 2007 09:16:00 +0000 Hits: 2,813