#官方默认插件中并无此插件,但官方还是提供了这个插件的下载
#注意:保证所有被监控机上都安装了sysstat包,并可以执行iostat命令
iostat的脚本如下:
-
#!/bin/sh
-
#
-
# Version 0.0.2 - Jan/2009
-
# Changes: added device verification
-
#
-
# by Thiago Varela - thiago@iplenix.com
-
-
iostat=`which iostat 2>/dev/null`
-
bc=`which bc 2>/dev/null`
-
-
function help {
-
exit -1
-
}
-
-
# Ensuring we have the needed tools:
-
( [ ! -f $iostat ] || [ ! -f $bc ] ) && \
-
( echo "ERROR: You must have iostat and bc installed in order to run this plugin" && exit -1 )
-
-
# Getting parameters:
-
while getopts "d:w:c:h" OPT; do
-
case $OPT in
-
"d") disk=$OPTARG;;
-
"w") warning=$OPTARG;;
-
"c") critical=$OPTARG;;
-
"h") help;;
-
esac
-
done
-
-
# Adjusting the three warn and crit levels:
-
crit_tps=`echo $critical | cut -d, -f1`
-
crit_read=`echo $critical | cut -d, -f2`
-
crit_written=`echo $critical | cut -d, -f3`
-
-
warn_tps=`echo $warning | cut -d, -f1`
-
warn_read=`echo $warning | cut -d, -f2`
-
warn_written=`echo $warning | cut -d, -f3`
-
-
-
# Checking parameters:
-
[ ! -b "/dev/$disk" ] && echo "ERROR: Device incorrectly specified" && help
-
-
( [ "$warn_tps" == "" ] || [ "$warn_read" == "" ] || [ "$warn_written" == "" ] || \
-
[ "$crit_tps" == "" ] || [ "$crit_read" == "" ] || [ "$crit_written" == "" ] ) &&
-
echo "ERROR: You must specify all warning and critical levels" && help
-
-
( [[ "$warn_tps" -ge "$crit_tps" ]] || \
-
[[ "$warn_read" -ge "$crit_read" ]] || \
-
[[ "$warn_written" -ge "$crit_written" ]] ) && \
-
echo "ERROR: critical levels must be highter than warning levels" && help
-
-
-
# Doing the actual check:
-
tps=`$iostat $disk | grep $disk | awk '{print $2}'`
-
kbread=`$iostat $disk | grep $disk | awk '{print $3}'`
-
kbwritten=`$iostat $disk | grep $disk | awk '{print $4}'`
-
-
-
# Comparing the result and setting the correct level:
-
if ( [ "`echo "$tps >= $crit_tps" | bc`" == "1" ] || [ "`echo "$kbread >= $crit_read" | bc`" == "1" ] || \
-
[ "`echo "$kbwritten >= $crit_written" | bc`" == "1" ] ); then
-
msg="CRITICAL"
-
status=2
-
else if ( [ "`echo "$tps >= $warn_tps" | bc`" == "1" ] || [ "`echo "$kbread >= $warn_read" | bc`" == "1" ] || \
-
[ "`echo "$kbwritten >= $warn_written" | bc`" == "1" ] ); then
-
msg="WARNING"
-
status=1
-
else
-
msg="OK"
-
status=0
-
fi
-
fi
-
-
# Printing the results:
-
echo "$msg - I/O stats tps=$tps KB_read/s=$kbread KB_written/s=$kbwritten | 'tps'=$tps; 'KB_read/s'=$kbread; 'KB_written/s'=$kbwritten;"
-
-
# Bye!
-
exit $status
#下载之后,放在每台被监控机的/usr/local/nagios/libexec/目录下
#然后更改属组,赋予可执行权限
在被监控机上/usr/local/nagios/etc/nrpe.cfg配置文件里添加
command[check_sda_iostat]=/usr/local/nagios/libexec/check_iostat -d sda -w 100 -c 200
在监控机/usr/local/nagios/etc/objects/commands.cfg里面添加
define command{
command_name check_iostat
command_line $USER1$/check_iostat -d $ARG1$ -w $ARG2$ -c $ARG3$
}
在监控机/usr/local/nagios/etc/servers/xxx.cfg里添加
define service{
use local-service
host_name xxxx
service_description iostat
check_command check_nrpe!check_iostat
}
然后检查配置是否有误
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
阅读(4066) | 评论(0) | 转发(0) |