From ff6018a3347a4a439645f5f5d5f2c9348c92deda Mon Sep 17 00:00:00 2001 From: Robert Ricci Date: Fri, 8 Mar 2002 18:32:10 +0000 Subject: [PATCH] Added some options to change the set of status gathered. By default, now only shows packet/octet couters. '-e' shows error counters, and '-a' shows all counters. --- tbsetup/portstats.in | 101 +++++++++++++++++++++++++++++++++---------- 1 file changed, 79 insertions(+), 22 deletions(-) diff --git a/tbsetup/portstats.in b/tbsetup/portstats.in index dc7baf4fc..eb2516adf 100755 --- a/tbsetup/portstats.in +++ b/tbsetup/portstats.in @@ -1,7 +1,12 @@ -#!/usr/bin/perl -w +#!/usr/bin/perl # -# portstats - Get port statistics for all nodes in an experiment +# portstats - Get port statistics for nodes in an experiment # +# +# NOTE: no -w, because $::line below is used in the eval, which perl +# can't pick up on, so it warns about this variable being only used once +# + # # Configure variables @@ -17,13 +22,41 @@ use Getopt::Long; use strict; sub usage { - print "Usage: $0 [vname ...] [vname:port ...]\n\n"; + print "Usage: $0 [-h] [vname ...] [vname:port ...]\n\n"; print "If only pid and eid are given, prints out information about all\n"; print "ports in the experiment. Otherwise, output is limited to the\n"; print "nodes and/or ports given.\n"; + print "\n"; + print "-h This message\n"; + print "-e Show only error counters\n"; + print "-a Show all stats\n"; return 1; } +# +# Process command-line arguments +# +my %opt = (); +GetOptions(\%opt,'h','a','e','p','b'); + +if ($opt{h}) { + exit &usage; +} + +my @oids = (); # The set of OIDs we care about + +if ($opt{a}) { + @oids = ('ifInOctets', 'ifInUcastPkts', 'ifInNUcastPkts', 'ifInDiscards', + 'ifInErrors', 'ifInUnknownProtos', 'ifOutOctets', 'ifOutUcastPkts', + 'ifOutNUcastPkts', 'ifOutDiscards', 'ifOutErrors', 'ifOutQLen'); +} elsif ($opt{e}) { + @oids = ('ifInDiscards', 'ifInErrors', 'ifInUnknownProtos', 'ifOutDiscards', + 'ifOutErrors'); +} else { + @oids = ('ifInOctets', 'ifInUcastPkts', 'ifInNUcastPkts', + 'ifOutOctets', 'ifOutUcastPkts', 'ifOutNUcastPkts'); +} + if (@ARGV < 2) { exit &usage; } @@ -31,6 +64,23 @@ my ($pid,$eid) = (shift,shift); my @passedPorts = @ARGV; +# +# This hash is used to create colmn headers and the format string +# +my %oids = ( + 'ifInOctets' => [[' In',' Octets'], '@>>>>>>>>>'], + 'ifInUcastPkts' => [[' InUnicast',' Packets'], '@>>>>>>>>>'], + 'ifInNUcastPkts' => [['InNUnicast',' Packets'], '@>>>>>>>>>'], + 'ifInDiscards' => [[' In',' Discards'], '@>>>>>>>>>'], + 'ifInErrors' => [[' In',' Errors'], '@>>>>>>>>>'], + 'ifInUnknownProtos' => [[' Unknown',' Protocol'], '@>>>>>>>>>'], + 'ifOutOctets' => [[' Out',' Octets'], '@>>>>>>>>>'], + 'ifOutUcastPkts' => [['OutUnicast',' Pakcets'], '@>>>>>>>>>'], + 'ifOutNUcastPkts' => [[' OutNUcast',' Packets'], '@>>>>>>>>>'], + 'ifOutDiscards' => [[' Out',' Discards'], '@>>>>>>>>>'], + 'ifOutErrors' => [[' Out',' Errors'], '@>>>>>>>>>'], + 'ifOutQLen' => [[' OutQueue',' Length'], '@>>>>>>>>>'] +); # # First, make sure the experiment exists @@ -84,9 +134,6 @@ if (@passedPorts) { # # List of OIDs we want to look at for each port # -my @oids = ('ifInOctets','ifInUcastPkts','ifInNUcastPkts','ifInDiscards', - 'ifInErrors','ifInUnknownProtos','ifOutOctets','ifOutUcastPkts', - 'ifOutNUcastPkts','ifOutDiscards','ifOutErrors','ifOutQLen'); # # Find out which devices these ports are on @@ -125,28 +172,38 @@ foreach my $name (keys %portMap) { } # -# Print out the column headers and define the output format +# Build up the heading a format strings # -my ($port, $inoctets, $inunicast, $innunicast, $indiscards, $inerr, $inunk, - $outoctets, $outunicast, $outnunicast, $outdiscards, $outerr,$outq); +my @heading1 = (' '); +my @heading2 = ('Port '); +my @format = ('@<<<<<<<<<<<<<'); + +foreach my $line (@oids{@oids}) { + my ($heading,$format) = @$line; + push @heading1, $$heading[0]; + push @heading2, $$heading[1]; + push @format, $format; +} -print << "END"; - In InUnicast InNUnicast In In Unknown Out OutUnicast OutNUcast Out Out OutQueue -Port Octets Packets Packets Discards Errors Protocol Octets Packets Packets Discards Errors Length ---------------------------------------------------------------------------------------------------------------------------------------------- -END -format stats = -@<<<<<<<<<<<<< @>>>>>>>>> @>>>>>>>>> @>>>>>>>>> @>>>>>>>>> @>>>>>>>>> @>>>>>>>>> @>>>>>>>>> @>>>>>>>>> @>>>>>>>>> @>>>>>>>>> @>>>>>>>>> @>>>>>>>>> -$port, $inoctets, $inunicast,$innunicast,$indiscards,$inerr, $inunk, $outoctets,$outunicast,$outnunicast,$outdiscards,$outerr,$outq -. +my $heading1 = join(" ",@heading1); +my $heading2 = join(" ",@heading2); + +my $format = "format stats =\n" . join(" ",@format) . "\n"; +$format .= join(",",map {"\$\$::line[$_]"} (0 .. @oids)) . "\n.\n"; + +eval $format; $FORMAT_NAME = 'stats'; +# +# Print out the heading +# +print "$heading1\n"; +print "$heading2\n"; +print "-" x length($heading1),"\n"; + # # Finally, print out the results # -foreach my $line (sort {$$a[0] cmp $$b[0]} @stats) { - ($port, $inoctets, $inunicast, $innunicast, $indiscards, $inerr, $inunk, - $outoctets, $outunicast, $outnunicast, $outdiscards, $outerr, $outq) - = @$line; +foreach $::line (sort {$$a[0] cmp $$b[0]} @stats) { write; } -- GitLab