citadel

My dotfiles, scripts and nix configs
git clone git://jb55.com/citadel
Log | Files | Refs | README | LICENSE

netbps (619B)


      1 #!/usr/bin/env perl
      2 use strict;
      3 use warnings;
      4 use Time::HiRes;
      5 
      6 my $reporting_interval = 10.0; # seconds
      7 my $bytes_this_interval = 0;
      8 my $start_time = [Time::HiRes::gettimeofday()];
      9 
     10 STDOUT->autoflush(1);
     11 
     12 while (<>) {
     13   if (/ length (\d+):/) {
     14     $bytes_this_interval += $1;
     15     my $elapsed_seconds = Time::HiRes::tv_interval($start_time);
     16     if ($elapsed_seconds > $reporting_interval) {
     17        my $bps = $bytes_this_interval / $elapsed_seconds;
     18        printf "%02d:%02d:%02d %10.2f Bps\n", (localtime())[2,1,0],$bps;
     19        $start_time = [Time::HiRes::gettimeofday()];
     20        $bytes_this_interval = 0;
     21     }
     22   }
     23 }