Commit 8b57a2f0 authored by Robert Ricci's avatar Robert Ricci

New script, portstats. Gets port counters for the ports in an experiment.

Usage: portstats <pid> <eid> [vname ...] [vname:port ...]

If only pid and eid are given, prints out information about all
ports in the experiment. Otherwise, output is limited to the
nodes and/or ports given.
parent 7c3853c8
...@@ -1212,6 +1212,7 @@ outfiles="$outfiles Makeconf GNUmakefile \ ...@@ -1212,6 +1212,7 @@ outfiles="$outfiles Makeconf GNUmakefile \
tbsetup/webmkgroup tbsetup/mkgroup \ tbsetup/webmkgroup tbsetup/mkgroup \
tbsetup/webmkacct tbsetup/mkacct tbsetup/eventsys_control \ tbsetup/webmkacct tbsetup/mkacct tbsetup/eventsys_control \
tbsetup/webmkproj tbsetup/mkproj tbsetup/libtestbed.pm \ tbsetup/webmkproj tbsetup/mkproj tbsetup/libtestbed.pm \
tbsetup/portstats \
tip/GNUmakefile \ tip/GNUmakefile \
tmcd/GNUmakefile tmcd/freebsd/GNUmakefile tmcd/linux/GNUmakefile \ tmcd/GNUmakefile tmcd/freebsd/GNUmakefile tmcd/linux/GNUmakefile \
tmcd/netbsd/GNUmakefile \ tmcd/netbsd/GNUmakefile \
......
...@@ -284,6 +284,7 @@ outfiles="$outfiles Makeconf GNUmakefile \ ...@@ -284,6 +284,7 @@ outfiles="$outfiles Makeconf GNUmakefile \
tbsetup/webmkgroup tbsetup/mkgroup \ tbsetup/webmkgroup tbsetup/mkgroup \
tbsetup/webmkacct tbsetup/mkacct tbsetup/eventsys_control \ tbsetup/webmkacct tbsetup/mkacct tbsetup/eventsys_control \
tbsetup/webmkproj tbsetup/mkproj tbsetup/libtestbed.pm \ tbsetup/webmkproj tbsetup/mkproj tbsetup/libtestbed.pm \
tbsetup/portstats \
tip/GNUmakefile \ tip/GNUmakefile \
tmcd/GNUmakefile tmcd/freebsd/GNUmakefile tmcd/linux/GNUmakefile \ tmcd/GNUmakefile tmcd/freebsd/GNUmakefile tmcd/linux/GNUmakefile \
tmcd/netbsd/GNUmakefile \ tmcd/netbsd/GNUmakefile \
......
...@@ -13,6 +13,7 @@ SUBDIRS = checkpass ns2ir ...@@ -13,6 +13,7 @@ SUBDIRS = checkpass ns2ir
BIN_STUFF = power snmpit tbend tbswapin tbswapout tbprerun tbreport \ BIN_STUFF = power snmpit tbend tbswapin tbswapout tbprerun tbreport \
os_load startexp endexp batchexp swapexp \ os_load startexp endexp batchexp swapexp \
node_reboot nscheck node_update savelogs node_control \ node_reboot nscheck node_update savelogs node_control \
portstats
# Stuff that mere users get on plastic. # Stuff that mere users get on plastic.
USERBINS = os_load node_reboot nscheck node_update savelogs node_control USERBINS = os_load node_reboot nscheck node_update savelogs node_control
......
#!/usr/bin/perl -w
#
# portstats - Get port statistics for all nodes in an experiment
#
#
# Configure variables
#
use lib '@prefix@/lib';
use libdb;
use snmpit_lib;
use snmpit_cisco;
use English;
use Getopt::Long;
use strict;
sub usage {
print "Usage: $0 <pid> <eid> [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";
return 1;
}
if (@ARGV < 2) {
exit &usage;
}
my ($pid,$eid) = (shift,shift);
my @passedPorts = @ARGV;
#
# First, make sure the experiment exists
#
if (!ExpState($pid,$eid)) {
die "There is no experiment $eid in project $pid\n";
}
#
# Make sure they have access to it
#
if (!TBExptAccessCheck($UID,$pid,$eid,TB_EXPT_READINFO)) {
die "You do not have permission to view experiment $pid/$eid\n";
}
snmpit_lib::init(0);
#
# Get a list of all ports in the experiment
#
my @experimentPorts = getExperimentPorts($pid,$eid);
my @ports;
if (@passedPorts) {
#
# Handle a set of passed-in ports
#
foreach my $port (@passedPorts) {
$port =~ /^([^:]+)(:(\d+))?$/;
my ($hostname,$portnumber) = ($1,$3);
my $nodeid;
if (!VnameToNodeid($pid,$eid,$hostname,\$nodeid)) {
die "There is no node $hostname in $pid/$eid\n";
}
if (defined($portnumber)) {
# They gave us a specific interface
push @ports, "$nodeid:$portnumber";
} else {
# We need to find all experimental ports for this node
push @ports, grep(/^$nodeid:(\d+)$/,@experimentPorts);
}
}
} else {
#
# They didn't ask for specific ports, so we'll use 'em all
#
@ports = @experimentPorts;
}
#
# 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
#
my %portMap = mapPortsToDevices(@ports);
my @stats;
foreach my $name (keys %portMap) {
my @ports = @{$portMap{$name}};
#
# Connect to the switch and get the data we want off of it
#
my $device = new snmpit_cisco($name);
my @results = $device->getFields(\@ports,\@oids);
foreach my $result (@results) {
my $port = shift @ports;
#
# Try to translate the port name to the node's vname
#
$port =~ /^(.+):(\d+)/;
if ($1) {
my $portnum = $2;
my ($junk, $vname);
NodeidToExp($1,\$junk,\$junk,\$vname);
$port = "$vname:$portnum";
}
#
# Throw this onto a list, so that we can sort it
#
push @stats, [$port,@$result];
}
}
#
# Print out the column headers and define the output format
#
my ($port, $inoctets, $inunicast, $innunicast, $indiscards, $inerr, $inunk,
$outoctets, $outunicast, $outnunicast, $outdiscards, $outerr,$outq);
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
.
$FORMAT_NAME = 'stats';
#
# 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;
write;
}
...@@ -11,7 +11,7 @@ use Exporter; ...@@ -11,7 +11,7 @@ use Exporter;
getTestSwitches getVlanPorts getExperimentVlans getDeviceNames getTestSwitches getVlanPorts getExperimentVlans getDeviceNames
getDeviceType getInterfaceSettings mapPortsToDevices getDeviceType getInterfaceSettings mapPortsToDevices
getSwitchStack getStackType getTrunks getTrunksFromSwitches getSwitchStack getStackType getTrunks getTrunksFromSwitches
tbsort ); getExperimentPorts tbsort );
use English; use English;
use libdb; use libdb;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment