Graphing HTTP response time with MRTG

2010-03-21 11:41:20
Graphing HTTP response time with MRTG
If you read my SLA Labbing post ealier you know that we were having trouble graphing Cisco SLA output in MRTG. The problem was the the MIB was not returning information that made graphable sense to MRTG. Which is when I got involved to write a script that would help us out.

This is how you would download snmp data from your router:

# snmpwalk -v 2c -c public 192.168.12.1 1.3.6.1.4.1.9.9.42.1.3.4.1.11.1
SNMPv2-SMI::enterprises.9.9.42.1.3.4.1.11.1.104057532 = Counter32: 329

And to make it more MRTG friendly:

# snmpwalk -v 2c -c public 192.168.12.1 1.3.6.1.4.1.9.9.42.1.3.4.1.11.1 | cut -d \: -f 4 | sed -e 's/ //g'
357

Regardless, I abandoned this when our graphs were not that helpful and moved on to another format. This script and resulting graph show the ping and http download speed to the web server in question. I realize there is a considerable amount of application latency built in, and the graphs also confirm this. Remember, Cisco sla takes great pains to eliminate the upper layer latency.

You can download this script in .tar or .pl. I have removed the perldoc formatting from the script below so that it render properly.

#!/usr/bin/perl
# 2009-10-13 Jud Bishop
# Please run perldoc on the script for more information.</code>

use strict;
use Time::HiRes qw(gettimeofday);
use LWP::Simple;

my $server = "192.168.24.234";
my $page = "/Prod/site/default.aspx";

# Should not have to change anything below this.
my $download = "http://" . $server . $page;

#Record time prior to request
my $start = gettimeofday();

# Test for successful download
if (head($download))
{
my $t = (gettimeofday() - $start) * 100;
printf ("%.4f \n", $t);
}
else {
print "0\n";
}

system "ping -c 1 $server | grep rtt | cut -d \= -f 2 | cut -d \/ -f 1 | sed -e 's/ //g'";

print "Web Response\n";
print "Ping Response\n";

=head1 NAME

web-ping.pl - A script to download a web page and ping a server to compare response times.

=head1 SYNOPSIS

A script that outputs the time in ms to download a webpage and ping a server.

=head1 DESCRIPTION

This is for graphing both page download and ping response time for MRTG.
The external command must return 4 lines of output:

Line 1 current state of the first variable, normally 'incoming bytes count' but it represents the web page load time.
Line 2 current state of the second variable, normally 'outgoing bytes count' but it represents the ping time.
Line 3 string (in any human readable format), telling the uptime of the target, not used.
Line 4 string, telling the name of the target, not used.

Put this in your 192.168.1.1.cfg file. You may need
to adjust the directories to match your configuration.

WorkDir: /usr/local/www/data-dist/stats/CircusStats2
Logformat: rrdtool
PathAdd: /usr/local/bin/
LibAdd: /usr/local/lib/perl5/site_perl/5.8.8/

Target[CircusStats-http]: `/usr/local/www/data/stats/configs/web-ping.pl`
Title[CircusStats-http]: Circus HTTP Response
PageTop[CircusStats-http]: Circus Response
LegendI[CircusStats-http]: HTTP Response
LegendO[CircusStats-http]: Ping Response
Ylegend[CircusStats-http]: Response in MS
Legend1[CircusStats-http]: HTTP Response
Legend2[CircusStats-http]: Ping Response
ShortLegend[CircusStats-http]: MS
routers.cgi*Options[CircusStats-http]: fixunit nototal nopercent nomax
routers.cgi*InCompact[CircusStats-http]: no
routers.cgi*Graph[CircusStats-http]: Circus-Combined noi

=head1 COPYRIGHT

Copyright 2009-10-13 Jud Bishop
Released under the GPLv2.
=cut

This is the resulting output from the script and MRTG configuration.

sla-mrtg

This entry was posted in Linux, Routing. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s