2008-09-21 15:19:06 +02:00
|
|
|
#! /usr/bin/perl
|
|
|
|
# This plugin based on http_responestime designed by Anders Nordby
|
|
|
|
#
|
2018-08-02 02:03:42 +02:00
|
|
|
# It is written to control the quality of an internet conneting by
|
2008-09-21 15:19:06 +02:00
|
|
|
# downloading a favicon.ico file from a lot - unlimited - count of
|
|
|
|
# domains.
|
|
|
|
#
|
|
|
|
# Don't forget zu fill in the following lines into the munin-node
|
|
|
|
# - ormally at /etc/muni/plugin-conf.d/ - an than restart munin
|
|
|
|
#
|
|
|
|
# [multi_http_responsetime]
|
|
|
|
# user root
|
|
|
|
# Jo Hartmann (Version 08-0912)
|
2011-04-28 10:11:42 +02:00
|
|
|
#
|
|
|
|
# Now working under munin 1.4.5
|
|
|
|
# Jo Hartmann (Version 11-0426)
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-09-21 15:19:06 +02:00
|
|
|
|
|
|
|
use Sys::Hostname;
|
|
|
|
use Time::HiRes qw( time );
|
|
|
|
use IO::Socket;
|
|
|
|
|
|
|
|
# ----- config -----
|
|
|
|
push(@url_array, "http://www.google.de");
|
|
|
|
push(@url_array, "http://www.t-online.de");
|
|
|
|
push(@url_array, "http://www.telekom.de");
|
|
|
|
push(@url_array, "http://www.ebay.de");
|
2011-04-28 10:11:42 +02:00
|
|
|
push(@url_array, "http://www.tus-vahrenwald.de");
|
2008-09-21 15:19:06 +02:00
|
|
|
$host = "localhost";
|
|
|
|
$comment = "HTTP-Ladezeiten von Web-Seiten";
|
|
|
|
#$host = hostname;
|
|
|
|
# ----- config -----
|
|
|
|
|
|
|
|
sub geturl {
|
|
|
|
my $data;
|
|
|
|
my $sock = new IO::Socket::INET (
|
|
|
|
PeerAddr => $host,
|
|
|
|
PeerPort => 80,
|
|
|
|
Proto => 'tcp'
|
|
|
|
);
|
|
|
|
return(0) unless ($sock);
|
|
|
|
print $sock "GET $baseurl HTTP/1.1\nHost: $vhost\nConnection: close\n\n";
|
|
|
|
while (<$sock>) {
|
|
|
|
$data .= $_;
|
|
|
|
}
|
|
|
|
close($sock);
|
|
|
|
|
|
|
|
# Debug
|
|
|
|
#my @response = split(/\n/, $data);
|
|
|
|
#my $httpresponse = $response[0];
|
|
|
|
#chomp($httpresponse);
|
|
|
|
#$httpresponse =~ s@\r@@g;
|
|
|
|
#print "HTTP response code: $httpresponse\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
sub cktime {
|
|
|
|
for ($i=0; $i <= $max_index; ++$i) {
|
|
|
|
$url = $url_array[$i], "/favicon.ico";
|
|
|
|
|
|
|
|
$vhost = $url;
|
|
|
|
$vhost =~ s@^\w+://(.+?)/.*@\1@;
|
|
|
|
|
|
|
|
$proto = $url;
|
|
|
|
$proto =~ s@^(\w+)://.*@\1@;
|
|
|
|
|
|
|
|
$baseurl = $url;
|
|
|
|
$baseurl =~ s@^\w+://.+?(/)@\1@;
|
|
|
|
|
|
|
|
$tick1 = time();
|
|
|
|
geturl;
|
|
|
|
$tick2 = time();
|
|
|
|
|
|
|
|
$tspent = $tick2-$tick1;
|
|
|
|
$msecs = ($tspent * 1000);
|
|
|
|
|
|
|
|
printf "timespent$i.value %.3f\n", $msecs;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Count of urls
|
|
|
|
$max_index = $#url_array;
|
|
|
|
|
|
|
|
if ($ARGV[0] && $ARGV[0] eq "autoconf") {
|
|
|
|
print "yes\n";
|
|
|
|
} elsif ($ARGV[0] && $ARGV[0] eq "config") {
|
|
|
|
if ($comment) {
|
2011-04-28 10:11:42 +02:00
|
|
|
print "graph_title $comment\n";
|
2008-09-21 15:19:06 +02:00
|
|
|
} else {
|
|
|
|
print "graph_title HTTP response time \n";
|
|
|
|
}
|
|
|
|
print "graph_scale no\n";
|
|
|
|
print "graph_vlabel ms\n";
|
2017-02-22 04:48:52 +01:00
|
|
|
print "graph_category webserver\n";
|
2008-09-21 15:19:06 +02:00
|
|
|
print "graph_info This graph shows the response time in milliseconds, to load a web page\n";
|
|
|
|
for ($i=0; $i <= $max_index; ++$i) {
|
|
|
|
$vhost = $url_array[$i];
|
|
|
|
$proto = $url_array[$i];
|
|
|
|
$vhost =~ s@^\w+://(.+?)/.*@\1@;
|
|
|
|
$proto =~ s@^(\w+)://.*@\1@;
|
|
|
|
|
2018-08-02 02:03:42 +02:00
|
|
|
# If url_array[] is a domain, vhost will be contain the the strinf "http://"
|
2008-09-21 15:19:06 +02:00
|
|
|
if($vhost =~ /http/) {
|
|
|
|
print "timespent$i.label $vhost\n";
|
|
|
|
} else {
|
2018-08-02 02:03:42 +02:00
|
|
|
print "timespent$i.label $proto://$vhost\n";
|
2008-09-21 15:19:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
print "timespent$i.info Ladezeit von $url_array[$i]/favicon.ico\n";
|
|
|
|
print "timespent$i.type GAUGE\n";
|
|
|
|
print "timespent$i.graph yes\n";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
cktime;
|
|
|
|
}
|