root / plugins / other / multi_http_responsetime @ af4a386b
Historique | Voir | Annoter | Télécharger (2,78 ko)
| 1 |
#! /usr/bin/perl |
|---|---|
| 2 |
# This plugin based on http_responestime designed by Anders Nordby |
| 3 |
# |
| 4 |
# It is written to control the quality of an internet conneting by |
| 5 |
# downloading a favicon.ico file from a lot - unlimited - count of |
| 6 |
# domains. |
| 7 |
# |
| 8 |
# Don't forget zu fill in the following lines into the munin-node |
| 9 |
# - ormally at /etc/muni/plugin-conf.d/ - an than restart munin |
| 10 |
# |
| 11 |
# [multi_http_responsetime] |
| 12 |
# user root |
| 13 |
# Jo Hartmann (Version 08-0912) |
| 14 |
# |
| 15 |
# Now working under munin 1.4.5 |
| 16 |
# Jo Hartmann (Version 11-0426) |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
use Sys::Hostname; |
| 22 |
use Time::HiRes qw( time ); |
| 23 |
use IO::Socket; |
| 24 |
|
| 25 |
# ----- config ----- |
| 26 |
push(@url_array, "http://www.google.de"); |
| 27 |
push(@url_array, "http://www.t-online.de"); |
| 28 |
push(@url_array, "http://www.telekom.de"); |
| 29 |
push(@url_array, "http://www.ebay.de"); |
| 30 |
push(@url_array, "http://www.tus-vahrenwald.de"); |
| 31 |
$host = "localhost"; |
| 32 |
$comment = "HTTP-Ladezeiten von Web-Seiten"; |
| 33 |
#$host = hostname; |
| 34 |
# ----- config ----- |
| 35 |
|
| 36 |
sub geturl {
|
| 37 |
my $data; |
| 38 |
my $sock = new IO::Socket::INET ( |
| 39 |
PeerAddr => $host, |
| 40 |
PeerPort => 80, |
| 41 |
Proto => 'tcp' |
| 42 |
); |
| 43 |
return(0) unless ($sock); |
| 44 |
print $sock "GET $baseurl HTTP/1.1\nHost: $vhost\nConnection: close\n\n"; |
| 45 |
while (<$sock>) {
|
| 46 |
$data .= $_; |
| 47 |
} |
| 48 |
close($sock); |
| 49 |
|
| 50 |
# Debug |
| 51 |
#my @response = split(/\n/, $data); |
| 52 |
#my $httpresponse = $response[0]; |
| 53 |
#chomp($httpresponse); |
| 54 |
#$httpresponse =~ s@\r@@g; |
| 55 |
#print "HTTP response code: $httpresponse\n"; |
| 56 |
} |
| 57 |
|
| 58 |
sub cktime {
|
| 59 |
for ($i=0; $i <= $max_index; ++$i) {
|
| 60 |
$url = $url_array[$i], "/favicon.ico"; |
| 61 |
|
| 62 |
$vhost = $url; |
| 63 |
$vhost =~ s@^\w+://(.+?)/.*@\1@; |
| 64 |
|
| 65 |
$proto = $url; |
| 66 |
$proto =~ s@^(\w+)://.*@\1@; |
| 67 |
|
| 68 |
$baseurl = $url; |
| 69 |
$baseurl =~ s@^\w+://.+?(/)@\1@; |
| 70 |
|
| 71 |
$tick1 = time(); |
| 72 |
geturl; |
| 73 |
$tick2 = time(); |
| 74 |
|
| 75 |
$tspent = $tick2-$tick1; |
| 76 |
$msecs = ($tspent * 1000); |
| 77 |
|
| 78 |
printf "timespent$i.value %.3f\n", $msecs; |
| 79 |
} |
| 80 |
} |
| 81 |
|
| 82 |
# Count of urls |
| 83 |
$max_index = $#url_array; |
| 84 |
|
| 85 |
if ($ARGV[0] && $ARGV[0] eq "autoconf") {
|
| 86 |
print "yes\n"; |
| 87 |
} elsif ($ARGV[0] && $ARGV[0] eq "config") {
|
| 88 |
if ($comment) {
|
| 89 |
print "graph_title $comment\n"; |
| 90 |
} else {
|
| 91 |
print "graph_title HTTP response time \n"; |
| 92 |
} |
| 93 |
print "graph_scale no\n"; |
| 94 |
print "graph_vlabel ms\n"; |
| 95 |
print "graph_category HTTP\n"; |
| 96 |
print "graph_info This graph shows the response time in milliseconds, to load a web page\n"; |
| 97 |
for ($i=0; $i <= $max_index; ++$i) {
|
| 98 |
$vhost = $url_array[$i]; |
| 99 |
$proto = $url_array[$i]; |
| 100 |
$vhost =~ s@^\w+://(.+?)/.*@\1@; |
| 101 |
$proto =~ s@^(\w+)://.*@\1@; |
| 102 |
|
| 103 |
# If url_array[] is a domain, vhost will be contain the the strinf "http://" |
| 104 |
if($vhost =~ /http/) {
|
| 105 |
print "timespent$i.label $vhost\n"; |
| 106 |
} else {
|
| 107 |
print "timespent$i.label $proto://$vhost\n"; |
| 108 |
} |
| 109 |
|
| 110 |
print "timespent$i.info Ladezeit von $url_array[$i]/favicon.ico\n"; |
| 111 |
print "timespent$i.type GAUGE\n"; |
| 112 |
print "timespent$i.graph yes\n"; |
| 113 |
} |
| 114 |
} else {
|
| 115 |
cktime; |
| 116 |
} |
