Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Re: Collecting ping times

by EyeOpener (Scribe)
on Aug 18, 2003 at 19:13 UTC ( [id://284682]=note: print w/replies, xml ) Need Help??


in reply to Re: Collecting ping times
in thread Collecting ping times

This was my thinking also, that one or more elements are undefined. However, even if that affects one pass, wouldn't the whole thing be cleared up in the next iteration? That is, shouldn't @times be effectively redefined for the next host? I can't figure out why every successive pass is screwed up in this way.

Since I can't force the problem, I have to wait for it to occur, which may be minutes or hours. I'd like to sprinkle some substantive t-shooting statements in here, but I can't figure out what will capture useful info. All suggestions welcome!

Replies are listed 'Best First'.
Re: Re: Re: Collecting ping times
by BrowserUk (Patriarch) on Aug 19, 2003 at 01:17 UTC

    Sorry! Amazing how you I can see what you I want to see, when I made the post it all made perfect sense, but I guess (as has been comprehensively brought to my attention:), I would have lost that bet...again.

    I've thrown everything I can think of at this code and I simply cannot make it fail, or produce the output you are seeing.

    Maybe if you posted the whole script someone would spot something. It really boggles the mind as to how the same print statement could print the first half of the output and omit the second. I tried redefining join to return undef, the empty list and several other variations, but the newline was always printed. I tried turning buffering off and on, and futzing with STDOUT in another thread, but I (now, belatedly, once my failing have been pointed out to me) cannot find a way to make this happen.


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller
    If I understand your problem, I can solve it! Of course, the same can be said for you.

      Here's the script in its entirety (running on ActiveState Perl 5.6.1 on an NT4 box, if it matters):

      use strict; use Getopt::Long; use Net::Ping; use Time::HiRes qw( gettimeofday tv_interval ); #vars my %args; my @hosts; #option defaults my $timeout = 3; my $yawn = 2; my $infile = 'pinger_time_hostlist.txt'; my $outfile = 'pinger_time_results.txt'; my $help; my $ok = GetOptions ( 'wait=i' => \$timeout, 'sleep=i' => \$yawn, 'inputfile=s' => \$infile, 'outputfile=s' => \$outfile, 'help' => \$help ); usage() if ! $ok || $help; #go! open OUT, ">>$outfile" or die "Can't open $outfile for writing: $!"; select OUT; $|=1; open(STDERR, ">&OUT"); open IN, "$infile" or die "Can't open $infile: $!"; while (<IN>) { chomp; s/\s*#.*//; push @hosts, $_ unless /^$/; } close IN; my $p = Net::Ping->new("icmp",$timeout,32); while (1) { foreach my $host (@hosts) { my @times; for (1..4) { my $t0 = [gettimeofday]; my $alive = $p->ping($host); my $t1 = tv_interval ($t0, [gettimeofday]); push @times, $alive ? # was ping successful? int($t1 * 1000) : # if so, record interval $timeout * 1000; # if not, record timeout val } my ($sec, $min, $hr, $day, $month, $year) = (localtime)[0..5]; my $timestamp = sprintf("%04d-%02d-%02d,%02d:%02d:%02d", $year + 1900, $month + 1, $day, $hr, $min, $sec); print "$timestamp,$host,", join ( ',', @times ), "\n"; } sleep $yawn; } $p->close(); sub usage { (my $msg = <<" MSG") =~ s/^\s{3}//mg; Usage: $0 [-w timeout] [-s sleep] [-i inputfile] [-o outputfile] [-h] Options: -w timeout Timeout in seconds to wait for each reply (default $timeout seconds) -s sleep Sleep time in seconds to pause after pinging through hostlist (default $yawn seconds) -i inputfile File containing list of hosts to ping (default $infile) -o outputfile Output log file (default $outfile) -h Displays this help MSG die $msg; }

      The input file is just a list of hosts separated by newlines. Comments begin with #. This really seems like a nice script... er, if it worked reliably. :-)

      I suspect this is being caused by some transient network condition or occurrence. (I wrote this thing because we're having trouble with our Qwest (ugh) VPNs.) However, like you, I can't force the error, and I can't figure out how it could cause the behavior I'm seeing. I'm starting to think this is <gulp> a bug in Perl or one of the modules I'm calling.

      Something might be happening to $p itself. I haven't tried moving this definition inside one of the loops, but that might be next. It's such a sporadic thing, though -- I've been running it since yesterday with no error, but I saw the problem four times between Friday and Monday. Aargh!

        Suggestion: Try commenting out this line:

        open(STDERR, ">&OUT");

        Or opening STDERR to a different file, and see if that prevents the problem from occurring.


        Examine what is said, not who speaks.
        "Efficiency is intelligent laziness." -David Dunham
        "When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller
        If I understand your problem, I can solve it! Of course, the same can be said for you.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://284682]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2024-04-16 19:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found