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};

In reply to Monitoring my www traffic lag by puudeli

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.