#!/bin/bash # netperf - Analyze the netstat running performance log, identifying # important results and trends. setglobal log = '"/Users/taylor/.netstatlog'" # change for your config setglobal stats = ""/tmp/netperf.stats.$Pid"" setglobal awktmp = ""/tmp/netperf.awk.$Pid"" trap "$[which rm] -f $awktmp $stats" 0 if test ! -r $log { echo "Error: can't read netstat log file $log" > !2 exit 1 } # First, report the basic statistics of the latest entry in the log file... eval $[tail -1 $log] # all values turn into shell variables setglobal rep = $[scriptbc -p 3 $re/$snt'*'100] setglobal repn = $[scriptbc -p 4 $re/$snt'*'10000 | cut -d. -f1] setglobal repn = "$shExpr(' $repn / 100 ')" setglobal retop = $[scriptbc -p 3 $reto/$snt'*'100]; setglobal retopn = $[scriptbc -p 4 $reto/$snt'*'10000 | cut -d. -f1] setglobal retopn = "$shExpr(' $retopn / 100 ')" setglobal dupp = $[scriptbc -p 3 $dup/$rec'*'100]; setglobal duppn = $[scriptbc -p 4 $dup/$rec'*'10000 | cut -d. -f1] setglobal duppn = "$shExpr(' $duppn / 100 ')" setglobal oop = $[scriptbc -p 3 $oo/$rec'*'100]; setglobal oopn = $[scriptbc -p 4 $oo/$rec'*'10000 | cut -d. -f1] setglobal oopn = "$shExpr(' $oopn / 100 ')" echo "Netstat is currently reporting the following:" /bin/echo -n " $snt packets sent, with $re retransmits ($rep%) " echo "and $reto retransmit timeouts ($retop%)" /bin/echo -n " $rec packets received, with $dup dupes ($dupp%)" echo " and $oo out of order ($oop%)" echo " $creq total connection requests, of which $cacc were accepted" echo "" ## Now let's see if there are any important problems to flag if test $repn -ge 5 { echo "*** Warning: Retransmits of >= 5% indicates a problem " echo "(gateway or router flooded?)" } if test $retopn -ge 5 { echo "*** Warning: Transmit timeouts of >= 5% indicates a problem " echo "(gateway or router flooded?)" } if test $duppn -ge 5 { echo "*** Warning: Duplicate receives of >= 5% indicates a problem " echo "(probably on the other end)" } if test $oopn -ge 5 { echo "*** Warning: Out of orders of >= 5% indicates a problem " echo "(busy network or router/gateway flood)" } # Now let's look at some historical trends... echo "Analyzing trends...." while read logline { eval $logline setglobal rep2 = $[scriptbc -p 4 $re / $snt '*' 10000 | cut -d. -f1] setglobal retop2 = $[scriptbc -p 4 $reto / $snt '*' 10000 | cut -d. -f1] setglobal dupp2 = $[scriptbc -p 4 $dup / $rec '*' 10000 | cut -d. -f1] setglobal oop2 = $[scriptbc -p 4 $oo / $rec '*' 10000 | cut -d. -f1] echo "$rep2 $retop2 $dupp2 $oop2" >> $stats } < $log echo "" # Now calculate some statistics, and compare them to the current values. cat << ''' > $awktmp { rep += $1; retop += $2; dupp += $3; oop += $4 } END { rep /= 100; retop /= 100; dupp /= 100; oop /= 100; print "reps="int(rep/NR) ";retops=" int(retop/NR) \ ";dupps=" int(dupp/NR) ";oops="int(oop/NR) } ''' > $awktmp { rep += $1; retop += $2; dupp += $3; oop += $4 } END { rep /= 100; retop /= 100; dupp /= 100; oop /= 100; print "reps="int(rep/NR) ";retops=" int(retop/NR) \ ";dupps=" int(dupp/NR) ";oops="int(oop/NR) } EOF eval $[awk -f $awktmp < $stats] if test $repn -gt $reps { echo "*** Warning: Retransmit rate is currently higher than average." echo " (average is $reps% and current is $repn%)" } if test $retopn -gt $retops { echo "*** Warning: Transmit timeouts are currently higher than average." echo " (average is $retops% and current is $retopn%)" } if test $duppn -gt $dupps { echo "*** Warning: Duplicate receives are currently higher than average." echo " (average is $dupps% and current is $duppn%)" } if test $oopn -gt $oops { echo "*** Warning: Out of orders are currently higher than average." echo " (average is $oops% and current is $oopn%)" } echo '('Analyzed $[wc -l < $stats] netstat log entries for calculations')' exit 0