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! :-)
In reply to Monitoring my www traffic lag by puudeli
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |