#!/bin/ksh # # Script: alarm_netidelta_1host # # Where: in $FEDIR/scripts where $FEDIR=/apps/nns_com/fea # # # Purpose: To check the host that this script runs on for 'exception'/'alarm' # conditions -- with respect to 'netstat -i': # like ethernet collisions # greater than 5 or 10% of packets-out CURRENTLY # (OR a very high packet in/out rate, like > 500 per 5sec). # # Checks 'delta' packet activity by interface (ec0) on a specified host # using the 'netstat -i' command. Gets a couple of 'netstat -i' # reports and differences them. # Ref: p.184 of 'System Performance Tuning', Mike Loukides, # O'Reilly & Associates, 1992 # # Opens an alarm-msg-window on the host specified in $1. # # Could send alarm messages/mail to I-DEAS Admin hosts/people # -- like iaw030/bmo01, iaw070/rgb07, iaw025/wcs05. # Also appends the alarm messages to file $2 (name passed to this script). # # # Called by: $FEDIR/scripts/alarm_scan script --- or manually # # Technique: 'alarm_scan' repeatedly does # # rsh iaw### script where ### is 000, 001, 002, ..., 100, ... # # where 'script' is this script # "$FEDIR/scripts/alarm_netidelta_1host $HOST4MSG" # # Written by: B. Montandon 5May97 to look for clients generating heavy I/O # on the 'sgia' file server -- or clients # clobbering themselves or their sub-net neighbors. # Updated by: B. Montandon 5May97 ############################################################################ # Set DISPLAY location for the following xwsh-winmsg display. ############################################################################ if test ! "$1" = "" then DISPLAY=${1}:0 export DISPLAY fi ############################################################################ # Set a work file (& list file, unused at this time). But could use an # in-memory variable instead of the work file. ############################################################################ # if test -w /local/scratch # then # OUTWORK=/local/scratch/topcpu_temp.all # # OUTLIST=/local/scratch/topcpu_temp.lis # else # OUTWORK=$HOME/topcpu_temp.all # # OUTLIST=$HOME/topcpu_temp.lis # fi ############################################################################ # Prepare alarm message heading. ############################################################################ HOSTNAME=`hostname` HOSTNAME3=`/usr/etc/arp $HOSTNAME` HOSTNAME2=`echo "$HOSTNAME3" |sed "s|-- no entry||"` # echo "*** $HOSTNAME2 ***" >> $1 IFACE="ec0" # LIMPERCENT=5 LIMPERCENT=10 # LIMRATE=100 LIMRATE=500 # # For test: # LIMRATE=1 SLEEPSECS=5 DATETIME=`date` WINMSG=`echo "\ ****************** $DATETIME ********************* THIS SGI WORKSTATION HAS EXPERIENCED AN Ethernet $IFACE 'IF' (InterFace) **PACKET-COLLISION-RATE** GREATER THAN ${LIMPERCENT}% --OR-- **PACKET-IN/OUT-RATE** GREATER THAN ${LIMRATE} per ${SLEEPSECS} seconds --- in the past ten seconds. *** HOST: $HOSTNAME2 *** %Collisions of Name Ipkts Ierrs Opkts Oerrs Collisions in+out out-only (Ipkts/sec) (Opkts/sec) ----- ------------ -------- ------------ -------- ------------ ------- -------- "` ############################################################################## ############### SAMPLE netstat -i OUTPUT ######################## ############################################################################## ## Output of '/usr/etc/netstat -i': ## ## Cols: ## ## Name Mtu Network Address Ipkts Ierrs Opkts Oerrs Coll ## ec0 1500 150.10.2 iaw030.cae.nns~ 69668 0 26274 0 229 ## lo0 8304 loopback localhost 5097 0 5097 0 0 ## ## ## Importance to this list: ## ## Name Mtu Network Address Ipkts Ierrs Opkts Oerrs Coll ## * * ** * ** ** ## ## Ref. O'Reilly Assoc. 'System Performance Tuning', p.181-184 & 187-194 ## See awk-based script to diff the netstat output, p.184. ################################################################################# # Difference two 'netstat -i' outputs -- about 5 secs apart. # Put this output in environment variables: # IPKTS1, IERRS1, OPKTS1, OERRS1, COLLS1 # IPKTS2, IERRS2, OPKTS2, OERRS2, COLLS2 ################################################################################ ################################################################################# # First 'netstat -s' snapshot. ################################################################################ SNAP1=`/usr/etc/netstat -i` # set -x IPKTS1=`echo "$SNAP1" | grep 'ec0' | awk '{print $5}'` IERRS1=`echo "$SNAP1" | grep 'ec0' | awk '{print $6}'` OPKTS1=`echo "$SNAP1" | grep 'ec0' | awk '{print $7}'` OERRS1=`echo "$SNAP1" | grep 'ec0' | awk '{print $8}'` COLLS1=`echo "$SNAP1" | grep 'ec0' | awk '{print $9}'` sleep $SLEEPSECS ################################################################################# # Second 'netstat -i' snapshot. ################################################################################ SNAP1=`/usr/etc/netstat -i` IPKTS2=`echo "$SNAP1" | grep 'ec0' | awk '{print $5}'` IERRS2=`echo "$SNAP1" | grep 'ec0' | awk '{print $6}'` OPKTS2=`echo "$SNAP1" | grep 'ec0' | awk '{print $7}'` OERRS2=`echo "$SNAP1" | grep 'ec0' | awk '{print $8}'` COLLS2=`echo "$SNAP1" | grep 'ec0' | awk '{print $9}'` ################################################################################# # Get the differences and attach the results line to WINMSG2. ################################################################################ # set -x IPKTS=`expr $IPKTS2 - $IPKTS1` IERRS=`expr $IERRS2 - $IERRS1` OPKTS=`expr $OPKTS2 - $OPKTS1` OERRS=`expr $OERRS2 - $OERRS1` COLLS=`expr $COLLS2 - $COLLS1` COLLPCTO=`expr 100 \* $COLLS / $OPKTS` COLLPCTIO=`expr 100 \* $COLLS / \( $OPKTS + $OPKTS \)` IRATE=`expr $IPKTS / $SLEEPSECS` ORATE=`expr $OPKTS / $SLEEPSECS` WINMSG2="" if test \( $IPKTS -gt $LIMRATE -o $OPKTS -gt $LIMRATE -o \ $COLLPCTO -gt $LIMPERCENT \) then WINMSG2=`echo "$IFACE $IPKTS $IERRS $OPKTS $OERRS $COLLS $COLLPCTIO $COLLPCTO" | \ awk '{printf ("\n %-5s %12d %8d %12d %8d %12d %7d %7d \n", \ $1, $2, $3, $4, $5, $6, $7, $8 ) }'` WINMSG2=$WINMSG2`echo "$IRATE $ORATE" | \ awk '{printf ("\n %8d %8d \n", \ $1, $2 ) }'` fi ############################################################################ # Display the alarm-msg display -- if WINMSG2 is not empty. ############################################################################ if test ! "$WINMSG2" = "" then WINMSG=${WINMSG}$WINMSG2 export WINMSG MSGLINES=`echo "$WINMSG" | wc -l` MSGLINES=`expr $MSGLINES + 5` ROWLOC=`date +%S` ROWLOC=`expr 10 \* $ROWLOC` # set -x # xwsh -bg gray78 -fg black -hold -autofork \ xwsh -bg red2 -fg snow1 -autofork \ -title "COLLISIONS_$HOSTNAME" -name "COLLISIONS_$HOSTNAME" \ -fn -*-screen-medium-r-normal--15-*-*-*-m-80-iso8859-1 \ -geometry 95x${MSGLINES}+080+${ROWLOC} -e /apps/nns_com/fea/scripts/winmsg fi # set -