root / plugins / http / http-response-times @ 17f78427
Historique | Voir | Annoter | Télécharger (2,62 ko)
| 1 | c1d1d335 | danny flack | #!/usr/bin/perl |
|---|---|---|---|
| 2 | use strict; |
||
| 3 | |||
| 4 | 17f78427 | Lars Kruse | # HTTP response times for either entire page views |
| 5 | c1d1d335 | danny flack | # or just the index, depending on configuration. |
| 6 | 17f78427 | Lars Kruse | # Full or index resource pulling is determined by the suffix of the |
| 7 | c1d1d335 | danny flack | # script name. ie. http_response_full or http_response_index |
| 8 | # |
||
| 9 | |||
| 10 | # Parameters: |
||
| 11 | 17f78427 | Lars Kruse | # |
| 12 | c1d1d335 | danny flack | # config |
| 13 | # |
||
| 14 | # Configuration variables: |
||
| 15 | # |
||
| 16 | # domain - domain of the server to measure (default takelessons.com) |
||
| 17 | # url[1..n] - url to measure against |
||
| 18 | |||
| 19 | my $domain = $ENV{'domain'} || 'http://takelessons.com';
|
||
| 20 | |||
| 21 | # determine the intended "action" of the script |
||
| 22 | # this is determined by the end of the script name |
||
| 23 | # http_response_full or http_response_index |
||
| 24 | my ($action) = ($0 =~ m/http_response_(\S+)$/); |
||
| 25 | $ENV{'action'} = $action;
|
||
| 26 | if (! $ENV{'action'} =~ m/(full|index)/) {
|
||
| 27 | die "invalid action (determined by script suffix)"; |
||
| 28 | } |
||
| 29 | |||
| 30 | my @urls; |
||
| 31 | |||
| 32 | #debug mode |
||
| 33 | #build urls manually |
||
| 34 | if ($ARGV[0] eq "debug") {
|
||
| 35 | push(@urls, ( "/", |
||
| 36 | "/san-diego-ca-92106/piano-lessons", |
||
| 37 | "/category/browse", |
||
| 38 | "/cities-music-lessons", |
||
| 39 | "/new-york-music-lessons", |
||
| 40 | "/category/singing-lessons")); |
||
| 41 | } |
||
| 42 | |||
| 43 | #get the urls - build from configuration variables |
||
| 44 | my $i = 1; |
||
| 45 | while (defined ($ENV{"url$i"})) {
|
||
| 46 | push(@urls, $ENV{"url$i"});
|
||
| 47 | $i++; |
||
| 48 | } |
||
| 49 | if (! @urls) {
|
||
| 50 | die "No urls defined\n"; |
||
| 51 | } |
||
| 52 | |||
| 53 | #output configuration and exit - required by Munin |
||
| 54 | if (exists $ARGV[0] and $ARGV[0] eq "config") {
|
||
| 55 | 17f78427 | Lars Kruse | print "graph_title $domain Site Response Times - $ENV{'action'}\n";
|
| 56 | 3c98d069 | dipohl | print "graph_category webserver\n"; |
| 57 | c1d1d335 | danny flack | print "graph_vlabel request time (seconds)\n"; |
| 58 | print "graph_info Response times for public areas of $domain.\n"; |
||
| 59 | |||
| 60 | foreach my $url (@urls) {
|
||
| 61 | 17f78427 | Lars Kruse | my $label = $url; |
| 62 | c1d1d335 | danny flack | #fix up our label name to be a valid variable name |
| 63 | 19f744ba | steelblade | $label =~ s@[^A-Za-z0-9_]@_@g; |
| 64 | c1d1d335 | danny flack | print "$label.label $url\n"; |
| 65 | print "$label.type GAUGE\n"; |
||
| 66 | } |
||
| 67 | |||
| 68 | exit 0; |
||
| 69 | |||
| 70 | } |
||
| 71 | |||
| 72 | |||
| 73 | |||
| 74 | #function to make the request and get the response time |
||
| 75 | sub req_time {
|
||
| 76 | 17f78427 | Lars Kruse | my $url = shift; |
| 77 | c1d1d335 | danny flack | my $time; |
| 78 | my $outdir = '/tmp/munin/' . int(rand(32000)); |
||
| 79 | system("mkdir -p $outdir");
|
||
| 80 | if ($ENV{'action'} eq "full") {
|
||
| 81 | 19f744ba | steelblade | $time = `/usr/bin/time -f "%e" wget -pq -P $outdir --header "Accept-Encoding: gzip,deflate" "$url" 2>&1`; |
| 82 | c1d1d335 | danny flack | } elsif ($ENV{'action'} eq "index") {
|
| 83 | 19f744ba | steelblade | $time = `/usr/bin/time -f "%e" wget -q -P $outdir --header "Accept-Encoding: gzip,deflate" "$url" 2>&1`; |
| 84 | c1d1d335 | danny flack | } |
| 85 | system("rm -rf $outdir");
|
||
| 86 | return $time; |
||
| 87 | } |
||
| 88 | |||
| 89 | #loop over every url and output the responses |
||
| 90 | foreach my $url (@urls) {
|
||
| 91 | 17f78427 | Lars Kruse | my $label = $url; |
| 92 | c1d1d335 | danny flack | #fix up our label name to be a valid name |
| 93 | 19f744ba | steelblade | $label =~ s@[^A-Za-z0-9_]@_@g; |
| 94 | c1d1d335 | danny flack | print "$label.value " . req_time($domain.$url); |
| 95 | } |
||
| 96 | |||
| 97 | exit 0; |
||
| 98 |
