# Updated: 2007-10-29 (i.yates@uea.ac.uk) - Fixed typos in usage!
# Updated: 2008-03-26 (i.yates@uea.ac.uk) - Fixed bug in critical/warning level checking which could result in erroneous results. Thanks to Drew Sudell for pointing this out!
usage(){
echo " check_iostat $VERSION - Nagios I/O statistics check script"
echo ""
echo " Usage: check_iostat -w -c -l -t|i|o|a [ -v ] [ -h ]"
echo ""
echo " NOTE: When specifying device, /dev/ is assumed, e.g. for /dev/hda0 you should just enter hda0 for the device"
echo ""
echo " -w Warning trigger level"
echo " -c Critical trigger level"
echo " -t I/O transactions per second (TPS/IOPS) on "
echo " -i Kilobytes read IN per second on "
echo " -o Kilobytes written OUT per second on "
echo " -a Kilobytes written OUT and read IN per Second on "
echo " -l Number of samples to take (must be greater than 1)"
echo " -v Verbose output (ignored for now)"
echo " -h Show this page"
echo "" }
## Process command line options
doopts(){ if( `test 0 -lt$#` )
then while getopts w:c:l:t:i:o:a:vh myarg "$@" do
case $myarg in
h|\?)
usage exit;;
w)
LEVEL_WARN=$OPTARG;;
c)
LEVEL_CRIT=$OPTARG;;
t)
FLAG_TPS=TRUE
DEVICE=$OPTARG;;
i)
FLAG_READS=TRUE
DEVICE=$OPTARG;;
o)
FLAG_WRITES=TRUE
DEVICE=$OPTARG;;
a)
FLAG_READWRITES=TRUE
DEVICE=$OPTARG;;
l)
COUNT=$OPTARG;;
v)
FLAG_VERBOSE=TRUE;; *)# Default
if[$COUNT-ge 2 ]; then $IOSTAT-k -d $DEVICE 1 $COUNT|$GREP$DEVICE|$TAIL-`expr $COUNT- 1` >$TMP else
RESULT="ERROR Count must be creater as 1"
EXIT_STATUS=$STATE_UNKNOWN
theend
fi
## General sanity check
if[-n "$LEVEL_WARN"-a -n "$LEVEL_CRIT"-a "$LEVEL_WARN"-lt"$LEVEL_CRIT"]; then ## Handle Transactions per second
if[$FLAG_TPS="TRUE"]; then
TPS=`cat $TMP|$AWK'{ sum += $2 } END { print sum / NR } '`
TPS_ABS=`echo $TPS|$AWK'{printf "%d",$1}'`
RESULTPERF="on $DEVICE| io=$TPS;$LEVEL_WARN;$LEVEL_CRIT;0;" if["$TPS_ABS"-lt"$LEVEL_WARN"]; then
RESULT="IOSTAT OK - $RESULTPERF"
EXIT_STATUS=$STATE_OK else if["$TPS_ABS"-ge"$LEVEL_CRIT"]; then
RESULT="IOSTAT CRITICAL - $RESULTPERF"
EXIT_STATUS=$STATE_CRITICAL else if["$TPS_ABS"-ge"$LEVEL_WARN"]; then
RESULT="IOSTAT WARNING - $RESULTPERF"
EXIT_STATUS=$STATE_WARNING
fi
fi
fi
fi
## Handle Reads per second
if[$FLAG_READS="TRUE"]; then
READSS=`CAT $TMP|$AWK'{ sum += $3} END { print sum / NR } '`
READSS_ABS=`echo $READSS|$AWK'{printf "%d",$1}'`
RESULTPERF="on $DEVICE| read=$READSS;$LEVEL_WARN;$LEVEL_CRIT;0;" if["$READSS_ABS"-lt"$LEVEL_WARN"]; then
RESULT="IOSTAT OK $RESULTPERF"
EXIT_STATUS=$STATE_OK else if["$READSS_ABS"-ge"$LEVEL_CRIT"]; then
RESULT="IOSTAT CRITICAL $RESULTPERF"
EXIT_STATUS=$STATE_CRITICAL else if["$READSS_ABS"-ge"$LEVEL_WARN"]; then
RESULT="IOSTAT WARNING $RESULTPERF"
EXIT_STATUS=$STATE_WARNING
fi
fi
fi
fi
## Handle Writes per second
if[$FLAG_WRITES="TRUE"]; then
WRITESS=`cat $TMP|$AWK'{ sum += $4} END { print sum / NR } '`
WRITESS_ABS=`echo $WRITESS|$AWK'{printf "%d",$1}'`
RESULTPERF="on $DEVICE| write=$WRITESS;$LEVEL_WARN;$LEVEL_CRIT;0;" if["$WRITESS_ABS"-lt"$LEVEL_WARN"]; then
RESULT="IOSTAT OK $RESULTPERF"
EXIT_STATUS=$STATE_OK else if["$WRITESS_ABS"-ge"$LEVEL_CRIT"]; then
RESULT="IOSTAT CRITICAL $RESULTPERF "
EXIT_STATUS=$STATE_CRITICAL else if["$WRITESS_ABS"-ge"$LEVEL_WARN"]; then
RESULT="IOSTAT WARNING $RESULTPERF"
EXIT_STATUS=$STATE_WARNING
fi
fi
fi
fi
## Handle Reads and Writes per second
if[$FLAG_READWRITES="TRUE"]; then
READSS=`cat $TMP|$AWK'{ sum += $3 } END { print sum / NR } '`
READSS_ABS=`echo $READSS|$AWK'{printf "%d",$1}'`
WRITESS=`cat $TMP|$AWK'{ sum += $4 } END { print sum / NR } '`
WRITESS_ABS=`echo $WRITESS|$AWK'{printf "%d",$1}'`
RESULTPERF="on $DEVICE| read=$READSS;$LEVEL_WARN;$LEVEL_CRIT;0; write=$WRITESS;$LEVEL_WARN;$LEVEL_CRIT;0 " if["$READSS_ABS"-lt"$LEVEL_WARN"]&&["$WRITESS_ABS"-lt"$LEVEL_WARN"]; then
RESULT="IOSTAT OK $RESULTPERF"
EXIT_STATUS=$STATE_OK else if["$READSS_ABS"-ge"$LEVEL_CRIT"]||["$WRITESS_ABS"-ge"$LEVEL_CRIT"]; then
RESULT="IOSTAT CRITICAL $RESULTPERF"
EXIT_STATUS=$STATE_CRITICAL else if["$READSS_ABS"-ge"$LEVEL_WARN"]||["$WRITESS_ABS"-ge"$LEVEL_WARN"]; then
RESULT="IOSTAT WARNING $RESULTPERF"
EXIT_STATUS=$STATE_WARNING
fi
fi
fi
fi else
echo "ERROR: Invalid warning/critical values"
usage exit
fi