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
SNMPv2-SMI::enterprises. = Counter32: 329

And to make it more MRTG friendly:

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

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.

# 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 = "";
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 - A script to download a web page and ping a server to compare response times.


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


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 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/`
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


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

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


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: Logo

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

Facebook photo

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

Connecting to %s