I've been dealing with an issue with my ISP for some time now where my ping speeds are extremely slow, when they send a tech out he just shurgs his shoulders and say it looks fine now so I asked them if I recorded some statistics on the ping speeds if that would help.
I did this test behind my router and directly connected to the modem.
Essentially I just ran a "ping myisp.com >> pingfile.txt" from my nix box and left it run for about 6 hours or so.
I then took that file and did the following against it so I would just have the ping response times
"cut -d= -f4 | cut -d' ' -f1 >> cut_ping.txt
so that left me with a file that would look like this (a short sample):
So then I wanted to get an average of the ping times (I chose perl to do this), that part was easy, I just read line by line, incremented a counter each time and added the values up - that's the simple math part.
I wanted to determine how many ping response fell into a certain range but for the life of me couldn't figure out how to use the range operator to do this.
What I have works but is ugly as sin.
I looked into Number::Range as well, but really that seems to come down to the same thing, I'd have to define all these ranges and then test my current line against those ranges (unless there's a more elegant way to use it) - which is essentially what I'm doing, I'd likely save myself some simple processing at the end.
Is there a better way to do what I've done?
The output looks like this
I did this test behind my router and directly connected to the modem.
Essentially I just ran a "ping myisp.com >> pingfile.txt" from my nix box and left it run for about 6 hours or so.
I then took that file and did the following against it so I would just have the ping response times
"cut -d= -f4 | cut -d' ' -f1 >> cut_ping.txt
so that left me with a file that would look like this (a short sample):
Code:
28.2
24.5
23.9
So then I wanted to get an average of the ping times (I chose perl to do this), that part was easy, I just read line by line, incremented a counter each time and added the values up - that's the simple math part.
I wanted to determine how many ping response fell into a certain range but for the life of me couldn't figure out how to use the range operator to do this.
What I have works but is ugly as sin.
I looked into Number::Range as well, but really that seems to come down to the same thing, I'd have to define all these ranges and then test my current line against those ranges (unless there's a more elegant way to use it) - which is essentially what I'm doing, I'd likely save myself some simple processing at the end.
Is there a better way to do what I've done?
Code:
#!/usr/bin/perl
use strict;
#clean up the ping output file by doing the following nix commands
#before running this
#cut -d= -f4 | cut -d' ' -f1 >> cut_ping.txt
#Variables
my $total=0;
my $average;
my $counter=0;
my $under50=0;
my $over500=0;
my $over600=0;
my $over700=0;
my $over800=0;
my $over900=0;
my $over1k=0;
my $over1100=0;
my $over1200=0;
#Logic
open pf, "cut_ping.txt";
foreach ( <pf> )
{
#Get some idea of the range of where the issues are
#could be cleaner if implementing the range module.
chomp($_);
if ($_ < 50 ){$under50++}
if ($_ > 500 ){$over500++}
if ($_ > 600){$over600++}
if ($_ > 700){$over700++}
if ($_ > 800){$over800++}
if ($_ > 900){$over900++}
if ($_ > 1000){$over1k++}
if ($_ > 1100){$over1100++}
if ($_ > 1200){$over1200++}
$counter++;
$total = $total + $_;
}
$average = $total / $counter;
#compute amount at each range
my $b500_600 = $over500 - $over600;
my $b600_700 = $over600 - $over700;
my $b700_800 = $over700 - $over800;
my $b800_900 = $over800 - $over900;
my $b900_1k = $over900 - $over1k;
my $b1k_1100 = $over1k - $over1100;
my $b1100_1200 = $over1100 - $over1200;
#Script Output
print "Total of " . $counter . " lines is " . $total . "\n";
print "Average Ping time is " . $average . "\n\n";
print "The ping time was under 50 " . $under50 . " times\n";
print "The ping time was between 500ms and 600ms " . $b500_600 . " times\n";
print "The ping time was between 600ms and 700ms " . $b600_700 . " times\n";
print "The ping time was between 700ms and 800ms " . $b700_800 . " times\n";
print "The ping time was between 800ms and 900ms " . $over800 . " times\n";
print "The ping time was between 900ms and 1000ms " . $over900 . " times\n";
print "The ping time was between 1000ms and 1100ms " . $b1k_1100 . " times\n";
print "The ping time was between 1100ms and 1200ms " . $b1100_1200 . " times\n";
print "The ping time was over 1200ms " . $over1200 . " times\n";
The output looks like this
Code:
Total of 28275 lines is 5120397.69999997
Average Ping time is 181.092756852342
The ping time was under 50 17532 times
The ping time was between 500ms and 600ms 575 times
The ping time was between 600ms and 700ms 441 times
The ping time was between 700ms and 800ms 475 times
The ping time was between 800ms and 900ms 1923 times
The ping time was between 900ms and 1000ms 1357 times
The ping time was between 1000ms and 1100ms 389 times
The ping time was between 1100ms and 1200ms 311 times
The ping time was over 1200ms 224 times