Created
March 1, 2017 22:40
-
-
Save tbaschak/b24711c13e013b6af74ee71f7deadcf4 to your computer and use it in GitHub Desktop.
Measures PPS coming out of tcpdump. Usage: `tcpdump -l -e -n ether broadcast | ./netpps`. Modified from http://superuser.com/questions/356907/how-to-get-real-time-network-statistics-in-linux-with-kb-mb-bytes-format-and-for
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use Time::HiRes; | |
my $reporting_interval = 5.0; # seconds | |
my $packets_this_interval = 0; | |
my $start_time = [Time::HiRes::gettimeofday()]; | |
STDOUT->autoflush(1); | |
while (<>) { | |
if (/ length (\d+):/) { | |
$packets_this_interval += 1; | |
my $elapsed_seconds = Time::HiRes::tv_interval($start_time); | |
if ($elapsed_seconds > $reporting_interval) { | |
my $pps = $packets_this_interval / $elapsed_seconds; | |
printf "%02d:%02d:%02d %10.2f PPS\n", (localtime())[2,1,0],$pps; | |
$start_time = [Time::HiRes::gettimeofday()]; | |
$packets_this_interval = 0; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment