#!/bin/sh # #NADDS Agent - http://nadds.drmadcow.net/ #disk i/o load agent #Agent Author: David Blizard #Date: 2003-May-26 (V3.0) . /usr/local/bcnu/etc/bcnuenv . $BCNUHOME/agent/agent_head #setup file handles and variables ERRFILE=$BCNUTMP/${BCNUAGENT}.err OUTFILE=$BCNUTMP/${BCNUAGENT}.out TMPFILE=$BCNUTMP/${BCNUAGENT}.tmp MSGFILE=$BCNUTMP/${BCNUAGENT}.msg STATFILE=$BCNUTMP/${BCNUAGENT}.status #dont touch these variables ERROR=0 WARN=0 ITERATOR=0 TPS_ERR_COUNT=0 BRD_ERR_COUNT=0 BWT_ERR_COUNT=0 #remove any old files rm -f $ERRFILE $OUTFILE $MSGFILE $TMPFILE $STATFILE 2>/dev/null #initialize status file echo "0" > $STATFILE 2>/dev/null #get and set BCNU paramaters param=$BCNUPARAM bcnu_param MAX_TPS=${p1:=1000} MAX_BLKRDPS=${p2:=1000} MAX_BLKWTPS=${p3:=1000} INTERVAL=${p4:=1} COUNT=${p5:=10} MAX_WARN=${p6:=1} #compensate for throwing out first line of iostat command MAXCOUNT=$COUNT COUNT=$[ $COUNT + 1 ] #get timestamp DATE=`date` #run the iostat command iostat -d $INTERVAL $COUNT | sed '4,/^Device/d' | sed '1,2d' | sed '/^$/,/^Device/d' > $OUTFILE 2>/dev/null if [ $? -ne 0 ] ; then BCNUMSG="$BCNU -m 'error - iostat command failed' -f $ERRFILE -e $BCNU_ERR -t $BCNUHOSTTYPE $BCNUHOST" bcnu_err_send exit 1 fi #format the data sed '1d' $OUTFILE | sort > $TMPFILE 2>/dev/null #prepare message file echo -e "\n|====Device Status====|\n" >> $MSGFILE 2>/dev/null cat $TMPFILE | while read DEVICE TPS BLK_READ_PS BLK_WRTN_PS BLK_READ BLK_WRITTEN 2>/dev/null do #chop off decimals, sorry no rounding TPS=`echo $TPS | sed 's/\.[0-9]*//'` BLK_READ_PS=`echo $BLK_READ_PS | sed 's/\.[0-9]*//'` BLK_WRTN_PS=`echo $BLK_WRTN_PS | sed 's/\.[0-9]*//'` #check for tps error and set status flag if [ $TPS -gt $MAX_TPS ] ;then TPS_ERR_COUNT=$[ $TPS_ERR_COUNT + 1 ] if [ $TPS_ERR_COUNT -gt $MAX_WARN ] ;then ERROR=1 else WARN=1 fi fi #check for blocks read error and set status flag if [ $BLK_READ_PS -gt $MAX_BLKRDPS ] ;then BRD_ERR_COUNT=$[ $BRD_ERR_COUNT + 1 ] if [ $BRD_ERR_COUNT -gt $MAX_WARN ] ;then ERROR=1 else WARN=1 fi fi #check for blocks written error and set status flag if [ $BLK_WRTN_PS -gt $MAX_BLKWTPS ] ;then BWT_ERR_COUNT=$[ $BWT_ERR_COUNT + 1 ] if [ $BWT_ERR_COUNT -gt $MAX_WARN ] ;then ERROR=1 else WARN=1 fi fi #count what report we are on ITERATOR=$[ $ITERATOR + 1 ] #if on last report log device status if [ $ITERATOR -eq $MAXCOUNT ] ;then if [ $ERROR -eq 1 ] ;then #set error level to status file echo "1" > $STATFILE 2>/dev/null echo -e "Device: $DEVICE Status: ERROR\n\t$TPS_ERR_COUNT Transfers Per Second errors\n\t$BRD_ERR_COUNT Blocks Read Per Second errors\n\t$BWT_ERR_COUNT Blocks Written Per Second errors" >> $MSGFILE 2>/dev/null elif [ $WARN -eq 1 ] ;then #read status level set to warn if ok read STATUS < $STATFILE 2>/dev/null if [ $STATUS -eq 0 ] ;then echo "2" > $STATFILE 2>/dev/null fi echo -e "Device: $DEVICE Status: WARNING\n\t$TPS_ERR_COUNT Transfers Per Second errors\n\t$BRD_ERR_COUNT Blocks Read Per Second errors\n\t$BWT_ERR_COUNT Blocks Written Per Second errors" >> $MSGFILE 2>/dev/null else echo -e "Device: $DEVICE Status: OK\n\t$TPS_ERR_COUNT Transfers Per Second errors\n\t$BRD_ERR_COUNT Blocks Read Per Second errors\n\t$BWT_ERR_COUNT Blocks Written Per Second errors" >> $MSGFILE 2>/dev/null fi #initialize for next device ITERATOR=0 ERROR=0 WARN=0 fi done #send bcnu message and data echo -e "\n|====iostat output - $DATE====|\n" >> $MSGFILE 2>/dev/null cat $OUTFILE >> $MSGFILE 2>/dev/null read STATUS < $STATFILE 2> /dev/null if [ $STATUS -eq 1 ] ;then BCNUMSG="$BCNU -m 'error - Disk Load Error Alert' -f $MSGFILE -e $BCNU_ERR -t $BCNUHOSTTYPE $BCNUHOST" bcnu_err_send elif [ $STATUS -eq 2 ] ;then BCNUMSG="$BCNU -m 'warning - Disk Load Warning Alert' -f $MSGFILE -e $BCNU_WARN -t $BCNUHOSTTYPE $BCNUHOST" bcnu_warn_send else BCNUMSG="$BCNU -m 'ok - Disks OK' -f $MSGFILE -e $BCNU_OK -t $BCNUHOSTTYPE $BCNUHOST" bcnu_send fi