Like humans, devices and applications in enterprises are also adept in
socializing with each other. Each application is interconnected with the other
for optimum performance. What connects all these devices and applications
running on them is the network, wired or wireless. This is the age of mobility
and devices are no longer sitting at one place. They move around and at the same
time need to be connected, all this puts a lot of importance on connectivity
which in turn is dependent on bandwidth. No matter how good your machine is and
no matter how good your application is, if the bandwidth of your Internet
connection is low, you won't be able to enjoy smooth browsing and all investment
in machines and applications would seem to be waste.
The same logic applies to modern data centers. If WAN connectivity is
bottle-necked then nothing can be done to improve performance of applications
running inside the data center. One way of avoiding bottle-necks is to plan data
center activities according to availability. For planning one needs data. In
this story, we talk about open source bandwidth monitoring tools that help one
to know the patterns of bandwidth availability.
Implementing MRTG
The best way to analyze huge chunks of data to derive patterns is via
graphs, and this is what Multi Router Traffic Grapher does. MRTG is a free
software licensed under the GNUGP. It displays graphs of traffic moving through
SNMP devices in your network. So whether you have a router or a firewall all you
need is MRTG. It is written in 'Perl' and works on Unix/Linux as well as
Windows, and even Netware systems. Here, we used a Windows XP machine to run it.
To enable SNMP client network service on the local host, go to Start>Control Panel> Add or Remove Programs> Add/Remove Windows Component and check Management and Monitoring Tools. |
This is the output of MRTG software. Here, besides the information like uptime and maximum speed one can also analyze traffic over five minutes, over a day, a week, and also over a year. |
The tools needed to run MRTG on Windows XP include MRTG software that can be
downloaded from http://oss.oetiker.ch/mrtg/pub/?M=D. We used the latest stable
version ie 'mrtg-2.16.3.zip' file. Besides MRTG you also need Active Perl for
running MRTG. This can be downloaded from http://www.activestate.com/activeperl/
(ActivePerl-5.10.1.1007-MSWin32-x86-291969.msi). In order to view created graphs
from anywhere, we used Apache Web Server that can be downloaded from http://httpd.apache.org/download.cgi#apache22
(apache_2.2.14-win32-x86-openssl-0.9.8k.msi). Once we have all the three
elements required, we can start with installing 'Perl' and 'Apache Web Server'
in their respective default paths. Once we have installed 'Perl,' we need to
check if a new Perl binary directory is listed in the system path. To do the
same go to Start> Right click My Computer> Properties> Advance tab> Environment
Variables and check for the following under System Variables:
PATH:
C:\Perl\site\bin;C:\Perl\bin;C:\Program
Files;C:\WINDOWS;C:\WINDOWS\System32
To check if Perl has been installed properly, go to command prompt and run
the following commands:
cd C:\Perl\eg
example.pl
And hit enter. You should get the following message:
Hello From ActivePerl!
If every thing is working fine, the next step is to extract
downloaded 'mrtg-2.16.3.zip' at 'C:\'. Once extracted we need to configure it.
Before that you need to check if MRTG is working properly. First we need to
enable SNMP client network service on the local host. For this, go to
Start>Control Panel> Add or Remove Programs> Add/Remove Windows Component and
put a check mark in front of Management and Monitoring Tools. Create a
'Test.pl' file at 'C:\mrtg-2.16.3\lib\mrtg2' and add the following code:
use BER;
use SNMP_Session;
# Return the uptime of the localhost to test SNMP
$host = "localhost";
$community = "public";
$oid = encode_oid(1,3,6,1,2,1,1,3,0); # Uptime
$session = SNMP_Session->open ($host, $community, 161)
|| die "Can't open SNMP session to localhost";
$session->get_request_response ($oid);
($bindings) = $session->decode_get_response ($session->{pdu_buffer});
($binding,$bindings) = &decode_sequence ($bindings);
($oid,$value) = &decode_by_template ($binding, "%O%@");
print &pretty_print($oid)," => ", &pretty_print ($value), "\n";
Now run the following command :
cd
C:\mrtg-2.16.3\lib\mrtg2
test.pl
This would show uptime of the machine. If everything is
working properly, it is time to create 'mrtg.cfg' file for monitoring traffic.
Run the following commands on command prompt to accomplish the same:
cd C:\mrtg-2.16.3\bin
perl cfgmaker public@192.168.5.25 > mrtg.cfg
Here '192.168.5.25' is the IP address of the router/machine
you are going to monitor (in our case it is a router). The next step is to
modify the 'mrtg.cfg' file so that it can dump output in a desired web server
folder (Apache in our case). We would also modify this file to continuously run
in the background. Open 'mrtg.cfg' in text editor and add the following lines
on top:
WorkDir:
C:\Progra~1\Apache~1\Apache2.2\htdocs
RunAsDaemon: yes
The path in front of 'WorkDir' is the path of Apache Web
Server. A key point to note here is that there should not be any spaces in this
path. This is the reason why we put 'Progra~1' instead of 'Program File'. Once
these changes have been saved, run the following commands:
cd C:\mrtg-2.16.3\bin
perl mrtg mrtg.cfg
One should get the following message on command prompt:
Daemonizing MRTG...
Do Not close this window. Or MRTG will die
Now open up your browser and go to the machine where MRTG
has been installed. This would show three graphs. The first graph is created to
show average traffic over five minutes while the other three have been created
for traffic movement over a week, month and year respectively. Besides traffic
graphs, one also comes to know about the uptime of router and maximum speed on
top.