2010-05-25 09:48:46 +02:00
|
|
|
#!/usr/bin/perl
|
|
|
|
use strict;
|
|
|
|
|
2018-08-02 02:03:42 +02:00
|
|
|
# HTTP response times for either entire page views
|
2010-05-25 09:48:46 +02:00
|
|
|
# or just the index, depending on configuration.
|
2018-08-02 02:03:42 +02:00
|
|
|
# Full or index resource pulling is determined by the suffix of the
|
2010-05-25 09:48:46 +02:00
|
|
|
# script name. ie. http_response_full or http_response_index
|
|
|
|
#
|
|
|
|
|
|
|
|
# Parameters:
|
2018-08-02 02:03:42 +02:00
|
|
|
#
|
2010-05-25 09:48:46 +02:00
|
|
|
# config
|
|
|
|
#
|
|
|
|
# Configuration variables:
|
|
|
|
#
|
|
|
|
# domain - domain of the server to measure (default takelessons.com)
|
|
|
|
# url[1..n] - url to measure against
|
|
|
|
|
|
|
|
my $domain = $ENV{'domain'} || 'http://takelessons.com';
|
|
|
|
|
|
|
|
# determine the intended "action" of the script
|
|
|
|
# this is determined by the end of the script name
|
|
|
|
# http_response_full or http_response_index
|
|
|
|
my ($action) = ($0 =~ m/http_response_(\S+)$/);
|
|
|
|
$ENV{'action'} = $action;
|
|
|
|
if (! $ENV{'action'} =~ m/(full|index)/) {
|
|
|
|
die "invalid action (determined by script suffix)";
|
|
|
|
}
|
|
|
|
|
|
|
|
my @urls;
|
|
|
|
|
|
|
|
#debug mode
|
|
|
|
#build urls manually
|
|
|
|
if ($ARGV[0] eq "debug") {
|
|
|
|
push(@urls, ( "/",
|
|
|
|
"/san-diego-ca-92106/piano-lessons",
|
|
|
|
"/category/browse",
|
|
|
|
"/cities-music-lessons",
|
|
|
|
"/new-york-music-lessons",
|
|
|
|
"/category/singing-lessons"));
|
|
|
|
}
|
|
|
|
|
|
|
|
#get the urls - build from configuration variables
|
|
|
|
my $i = 1;
|
|
|
|
while (defined ($ENV{"url$i"})) {
|
|
|
|
push(@urls, $ENV{"url$i"});
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
if (! @urls) {
|
|
|
|
die "No urls defined\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
#output configuration and exit - required by Munin
|
|
|
|
if (exists $ARGV[0] and $ARGV[0] eq "config") {
|
2018-08-02 02:03:42 +02:00
|
|
|
print "graph_title $domain Site Response Times - $ENV{'action'}\n";
|
2017-02-21 17:11:23 +01:00
|
|
|
print "graph_category webserver\n";
|
2010-05-25 09:48:46 +02:00
|
|
|
print "graph_vlabel request time (seconds)\n";
|
|
|
|
print "graph_info Response times for public areas of $domain.\n";
|
|
|
|
|
|
|
|
foreach my $url (@urls) {
|
2018-08-02 02:03:42 +02:00
|
|
|
my $label = $url;
|
2010-05-25 09:48:46 +02:00
|
|
|
#fix up our label name to be a valid variable name
|
2010-11-17 19:36:35 +01:00
|
|
|
$label =~ s@[^A-Za-z0-9_]@_@g;
|
2010-05-25 09:48:46 +02:00
|
|
|
print "$label.label $url\n";
|
|
|
|
print "$label.type GAUGE\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
exit 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#function to make the request and get the response time
|
|
|
|
sub req_time {
|
2018-08-02 02:03:42 +02:00
|
|
|
my $url = shift;
|
2010-05-25 09:48:46 +02:00
|
|
|
my $time;
|
|
|
|
my $outdir = '/tmp/munin/' . int(rand(32000));
|
|
|
|
system("mkdir -p $outdir");
|
|
|
|
if ($ENV{'action'} eq "full") {
|
2010-11-17 19:36:35 +01:00
|
|
|
$time = `/usr/bin/time -f "%e" wget -pq -P $outdir --header "Accept-Encoding: gzip,deflate" "$url" 2>&1`;
|
2010-05-25 09:48:46 +02:00
|
|
|
} elsif ($ENV{'action'} eq "index") {
|
2010-11-17 19:36:35 +01:00
|
|
|
$time = `/usr/bin/time -f "%e" wget -q -P $outdir --header "Accept-Encoding: gzip,deflate" "$url" 2>&1`;
|
2010-05-25 09:48:46 +02:00
|
|
|
}
|
|
|
|
system("rm -rf $outdir");
|
|
|
|
return $time;
|
|
|
|
}
|
|
|
|
|
|
|
|
#loop over every url and output the responses
|
|
|
|
foreach my $url (@urls) {
|
2018-08-02 02:03:42 +02:00
|
|
|
my $label = $url;
|
2010-05-25 09:48:46 +02:00
|
|
|
#fix up our label name to be a valid name
|
2010-11-17 19:36:35 +01:00
|
|
|
$label =~ s@[^A-Za-z0-9_]@_@g;
|
2010-05-25 09:48:46 +02:00
|
|
|
print "$label.value " . req_time($domain.$url);
|
|
|
|
}
|
|
|
|
|
|
|
|
exit 0;
|
|
|
|
|
|
|
|
|