root / plugins / http / http_responsetime @ c4b2d9a8
Historique | Voir | Annoter | Télécharger (1,6 ko)
| 1 | df0cf8d3 | Anders Nordby | #! /usr/bin/perl |
|---|---|---|---|
| 2 | # anders@aftenposten.no, 2007-04-11 |
||
| 3 | # Shows the response time to fetch a web page |
||
| 4 | |||
| 5 | use Sys::Hostname; |
||
| 6 | use Time::HiRes qw( time ); |
||
| 7 | use IO::Socket; |
||
| 8 | |||
| 9 | # ----- config ----- |
||
| 10 | $url = "http://cache.mydomain.org/img/logocomp.gif"; |
||
| 11 | $host = "localhost"; |
||
| 12 | $comment = "2K Comp logo from localhost"; |
||
| 13 | #$host = hostname; |
||
| 14 | # ----- config ----- |
||
| 15 | |||
| 16 | sub geturl {
|
||
| 17 | my $data; |
||
| 18 | my $sock = new IO::Socket::INET ( |
||
| 19 | PeerAddr => $host, |
||
| 20 | PeerPort => 80, |
||
| 21 | Proto => 'tcp' |
||
| 22 | ); |
||
| 23 | return(0) unless ($sock); |
||
| 24 | print $sock "GET $baseurl HTTP/1.1\nHost: $vhost\nConnection: close\n\n"; |
||
| 25 | while (<$sock>) {
|
||
| 26 | $data .= $_; |
||
| 27 | } |
||
| 28 | close($sock); |
||
| 29 | |||
| 30 | # Debug |
||
| 31 | #my @response = split(/\n/, $data); |
||
| 32 | #my $httpresponse = $response[0]; |
||
| 33 | #chomp($httpresponse); |
||
| 34 | #$httpresponse =~ s@\r@@g; |
||
| 35 | #print "HTTP response code: $httpresponse\n"; |
||
| 36 | } |
||
| 37 | |||
| 38 | sub cktime {
|
||
| 39 | $vhost = $url; |
||
| 40 | $vhost =~ s@^\w+://(.+?)/.*@\1@; |
||
| 41 | |||
| 42 | $proto = $url; |
||
| 43 | $proto =~ s@^(\w+)://.*@\1@; |
||
| 44 | |||
| 45 | $baseurl = $url; |
||
| 46 | $baseurl =~ s@^\w+://.+?(/)@\1@; |
||
| 47 | |||
| 48 | $tick1 = time(); |
||
| 49 | geturl; |
||
| 50 | $tick2 = time(); |
||
| 51 | |||
| 52 | $tspent = $tick2-$tick1; |
||
| 53 | $msecs = ($tspent * 1000); |
||
| 54 | |||
| 55 | printf "timespent.value %.3f\n", $msecs; |
||
| 56 | } |
||
| 57 | |||
| 58 | if ($ARGV[0] && $ARGV[0] eq "autoconf") {
|
||
| 59 | print "yes\n"; |
||
| 60 | } elsif ($ARGV[0] && $ARGV[0] eq "config") {
|
||
| 61 | if ($comment) {
|
||
| 62 | print "graph_title HTTP response time ($comment)\n"; |
||
| 63 | } else {
|
||
| 64 | print "graph_title HTTP response time\n"; |
||
| 65 | } |
||
| 66 | print "graph_vlabel ms\n"; |
||
| 67 | c4b2d9a8 | dipohl | print "graph_category webserver\n"; |
| 68 | df0cf8d3 | Anders Nordby | print "graph_info This graph shows the response time in milliseconds, to load a web page\n"; |
| 69 | print "timespent.label timespent\n"; |
||
| 70 | print "timespent.type GAUGE\n"; |
||
| 71 | print "timespent.graph yes\n"; |
||
| 72 | } else {
|
||
| 73 | cktime; |
||
| 74 | } |
