I suffered a lot from lagging network (http/https) at $work and needed some proof for the ICT support desk to backup my claims and force them to take some action. So, I wrote this little piece of code to generate simple timing statistics for gnuplot.

#! /usr/bin/perl use strict; use warnings; use English qw( -no_match_vars ); use WWW::Mechanize; use constant TRUE => 1; { usage() if @ARGV != 2; my $url = shift; my $data_file = shift; my ($fj, $start, $end, $spent, $gap, $date, $resp); my $fh; open( $fh, '>', $data_file ) or die "Unable to open '$data_file' : + $OS_ERROR"; my $mech = WWW::Mechanize->new(); while ( TRUE ) { my($hour, $min) = (localtime())[2,1]; $date = sprintf("%02d:%02d", $hour, $min); $start = time(); $resp = undef; if( eval { $resp = $mech->get($url); 1 } ) { $end = time(); $spent = $end - $start; } else { $spent = undef; } print $fh "$date\t" . (defined($spent) ? $spent : 'undef') . " +\n"; print "$date\t" . (defined($spent) ? $spent : 'undef') . "\n"; if( $spent ) { $gap = ( $spent >= 30 ? 0 : 30 - $spent ); } else { $gap = 30; } sleep $gap; } } sub usage { print <<"EOF"; Usage: $PROGRAM_NAME <url> <outfile> Fetch <url> and write the time spent (in seconds) into <outfile>. URL is fetched every 30 seconds. The time spent fetching the URL is subtracted from the sleeped time and is set to zero if it exceeds 30 seconds. Timing infor is printed into the outfile and STDOUT in the following format: hour:min\\t<seconds> For example 13:53 0 13:54 1 EOF exit 1; }

With the help of this little scripture I convinced the ICT support to put my IP address in the proxy-by-pass list and now I am free to surf the internet! :-)

--
seek $her, $from, $everywhere if exists $true{love};

Replies are listed 'Best First'.
Re: Monitoring my www traffic lag
by Tanktalus (Canon) on Feb 26, 2009 at 20:10 UTC

    Just as a side note, I find that far too many people are unduly impressed by large numbers of extra decimal points. Pull out Time::HiRes, and you, too, can be far more accurate than your error margin allows ;-)

    I realise that in your case, your problem was solved, but in the future, some people may want to pull out the extra 5 or 6 decimal places just for overimpressiveness :-)

      I did consider Time::HiRes but thought it to be a bit overkill, since the lag was from 1 second to 90 seconds and around 1/3 of all requests failed. Of course if people require finer granularity they can substitute the timer :-)

      --
      seek $her, $from, $everywhere if exists $true{love};