Опубликовано

Пришла мне в голову идея через mrtg стороить граффик Http Response при загрузке определенного сайта. Погуглив достаточно много был найден приведенный ниже скрипт. Однако в данном скрипте указана не верная настройка mrtg.

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

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

Поэтому привожу ниже свои настройки в mrtg.cfg

Target[web-http1]: `export LANG=C; perl /usr/local/sbin/mrtg/web-ping1.pl`
MaxBytes[web-http1]: 300
Options[web-http1]: gauge, nopercent
Unscaled[web-http1]: dwym
YLegend[web-http1]: Response in msec
ShortLegend[web-http1]: msec
LegendO[web-http1]: Ping Response
LegendI[web-http1]: HTTP Respons
Title[web-http1]: ваш_хост
PageTop[web-http1]:

HTTP Response for ваш_хост

System: ваш_хост

После чего ждем обновление данных и смотрим графики

Share and Enjoy:
  • Мой Мир
  • Facebook
  • Twitter

Добавить комментарий