-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnetbps.pl
executable file
·33 lines (28 loc) · 922 Bytes
/
netbps.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/perl
use strict;
use warnings;
use Time::HiRes;
my $reporting_interval = 0.5; # seconds
my $bytes_this_interval = 0;
my $start_time = [Time::HiRes::gettimeofday()];
my $avg_Mbps = 0;
my $count=0;
STDOUT->autoflush(1);
while (<>) {
if (/ length (\d+):/) {
$bytes_this_interval += $1;
my $elapsed_seconds = Time::HiRes::tv_interval($start_time);
if ($elapsed_seconds > $reporting_interval) {
my $bps = $bytes_this_interval / $elapsed_seconds;
my $Mbps = ($bps*8)/(1024*1024);
if ($count != 0){
$avg_Mbps = (($count - 1)*$avg_Mbps + $Mbps)/$count;
}
printf "count = %d %02d:%02d:%02d %10.2f Mbps Avg=%10.2f \n", $count, (localtime())[2,1,0],$Mbps,$avg_Mbps;
$count += 1;
#printf "%02d:%02d:%02d %10.2f Mbps\n", (localtime())[2,1,0],$bps;
$start_time = [Time::HiRes::gettimeofday()];
$bytes_this_interval = 0;
}
}
}