ethstats (1.0-4) 02-interface.patch

Summary

 ethstats.pl |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

    
download this patch

Patch contents

Description: Allow a single interface to be watched.
Author: Peter Pentchev <roam@ringlet.net>
Last-Modified: 2010-04-16

--- a/ethstats.pl
+++ b/ethstats.pl
@@ -27,14 +27,17 @@
 #  eth1: 2039952   21982    6    0    0     6          0         0 47000710   34813    0    0    0   821       0          0
 
 my %opts;
+my $iface;
 
-getopts('n:t', \%opts) or die("Usage: ethstats [-t] [-n period]\n");
+getopts('i:n:t', \%opts) or
+    die("Usage: ethstats [-t] [-i iface] [-n period]\n");
 $addtime = 1 if defined($opts{'t'});
 if (defined($opts{'n'})) {
 	die("The period must be a positive integer\n")
 	    unless $opts{'n'} =~ /^([1-9]\d*)$/;
 	$period = $1;
 }
+$iface = $opts{'i'}; # also works if it isn't defined
 
 $op = $period;
 $period = 1;
@@ -68,6 +71,7 @@
     chop($l);
     ($dev, $rest) = split(/:/, $l);
     $dev  =~ s/\s//g;
+    next if defined($iface) && $dev ne $iface;
     $rest =~ s/^\s+//;
     @devarr = split(/\s+/, $rest);
     $bytesin{$dev} = @devarr[0]; $bytesout{$dev} = @devarr[8];