Cover V07, I05
Article
Figure 1
Figure 2
Listing 1
Listing 2
Listing 3
Listing 4
Listing 5

may98.tar


Listing 2: Simple script for logging network statistics

#!/usr/local/bin/perl -w

#
#  netstats.pl  --  Collect network collision statistics
#
#    Output:
#         ctime   Opkts Collisions
#       --------- ----- ----------
#       873075733 92001 459
#

$LogFile = "/var/stats/netstats.messages";
local($Iface,$mtu,$net,$addr,$Ipkts,$Ierrs,$Opkts,$Oerrs,$Collis,$Queue);

# Output from "netstat -i" on Solaris 2.5.1 looks like:
#  Name  Mtu  Net/Dest      Address   Ipkts   Ierrs Opkts Oerrs Collis Queue
#  lo0   8232 loopback      localhost  131     0     131    0     0      0
#  le0   1500 160.129.40.0  atlas      3812928 0     92341  1     459    0
#
open (NETSTAT_FD, "/usr/bin/netstat -i |");
while (<NETSTAT_FD>) {
if (/^le0/) {
($Iface,$mtu,$net,$addr,$Ipkts,$Ierrs,$Opkts,$Oerrs,$Collis,$Queue)
= split();
last;
}
}

# Write out the current time and the netstat data to the log file
#
open (LOGFILE_FD, ">>$LogFile") || die "Can't open $LogFile for writing";
#print LOGFILE_FD "  ctime   Opkts Collisions\n";
#print LOGFILE_FD "--------- ----- ----------\n";
local($now) = time();
print LOGFILE_FD "$now $Opkts $Collis\n";

# End of File