chech_io_bio脚本内容如下:
#!/bin/sh
#
# Version 0.0.1 - Jan/2017
# Changes: added device verification
#
# by curious
vmstat=`which vmstat 2>/dev/null`
bc=`which bc 2>/dev/null`
function help {
echo -e "\n\t此功能为检测主机I/O是否达到瓶颈,检测参数为bi和bo。\n\t一般情况bi+bo<1000。如果bi+bo>1000且wa>20(wa越高,表示I/O等待越严重),则考虑提高磁盘的读写性能\n\t-w <bi+bo警告阈值>,<wa警告阈值> \n\t-c <bi+bo critical阈值>,<wa critical阈值>\n\t \n"
exit -1
}
# Ensuring we have the needed tools:
( [ ! -f $vmstat ] || [ ! -f $bc ] ) && \
( echo "ERROR: You must have vmstat and bc installed in order to run this plugin" && exit -1 )
# Getting parameters:
while getopts "w:c:h" OPT; do
case $OPT in
"w") warning=$OPTARG;;
"c") critical=$OPTARG;;
"h") help;;
esac
done
# Adjusting the three warn and crit levels:
crit_bio=`echo $critical | cut -d, -f1`
crit_wa=`echo $critical | cut -d, -f2`
warn_bio=`echo $warning | cut -d, -f1`
warn_wa=`echo $warning | cut -d, -f2`
# Checking parameters:
( [[ "$warn_bio" -ge "$crit_bio" ]] || \
[[ "$warn_wa" -ge "$crit_wa" ]] ) && \
echo "ERROR: critical levels must be highter than warning levels" && help
# Doing the actual check:
si=`$vmstat 1 2| tail -1 | awk '{print $9}'`
so=`$vmstat 1 2| tail -1 | awk '{print $10}'`
wa=`$vmstat 1 2| tail -1 | awk '{print $16}'`
bio=`echo "$si+$so"|bc`
# Checking parameters:
( [[ "$warn_bio" -ge "$crit_bio" ]] || \
[[ "$warn_wa" -ge "$crit_wa" ]] ) && \
echo "ERROR: critical levels must be highter than warning levels" && help
# Comparing the result and setting the correct level:
if ( [ "`echo "$bio >= $crit_bio" | bc`" == "1" ] && [ "`echo "$wa >= $crit_wa" | bc`" == "1" ] ); then
msg="CRITICAL"
status=2
else if ( [ "`echo "$bio >= $warn_bio" | bc`" == "1" ] && [ "`echo "$wa >= $warn_wa" | bc`" == "1" ] ); then
msg="WARNING"
status=1
else
msg="OK"
status=0
fi
fi
# Printing the results:
echo "$msg - IO bi/so/wa stats bio=$bio wa=$wa | 'bio'=$bio;$warn_bio;$crit_bio 'wa'=$wa;$warn_wa;$crit_wa"
# Bye!
exit $status
#!/bin/sh
#
# Version 0.0.1 - Jan/2017
# Changes: added device verification
#
# by curious
vmstat=`which vmstat 2>/dev/null`
bc=`which bc 2>/dev/null`
function help {
echo -e "\n\t此功能为检测主机I/O是否达到瓶颈,检测参数为bi和bo。\n\t一般情况bi+bo<1000。如果bi+bo>1000且wa>20(wa越高,表示I/O等待越严重),则考虑提高磁盘的读写性能\n\t-w <bi+bo警告阈值>,<wa警告阈值> \n\t-c <bi+bo critical阈值>,<wa critical阈值>\n\t \n"
exit -1
}
# Ensuring we have the needed tools:
( [ ! -f $vmstat ] || [ ! -f $bc ] ) && \
( echo "ERROR: You must have vmstat and bc installed in order to run this plugin" && exit -1 )
# Getting parameters:
while getopts "w:c:h" OPT; do
case $OPT in
"w") warning=$OPTARG;;
"c") critical=$OPTARG;;
"h") help;;
esac
done
# Adjusting the three warn and crit levels:
crit_bio=`echo $critical | cut -d, -f1`
crit_wa=`echo $critical | cut -d, -f2`
warn_bio=`echo $warning | cut -d, -f1`
warn_wa=`echo $warning | cut -d, -f2`
# Checking parameters:
( [[ "$warn_bio" -ge "$crit_bio" ]] || \
[[ "$warn_wa" -ge "$crit_wa" ]] ) && \
echo "ERROR: critical levels must be highter than warning levels" && help
# Doing the actual check:
si=`$vmstat 1 2| tail -1 | awk '{print $9}'`
so=`$vmstat 1 2| tail -1 | awk '{print $10}'`
wa=`$vmstat 1 2| tail -1 | awk '{print $16}'`
bio=`echo "$si+$so"|bc`
# Checking parameters:
( [[ "$warn_bio" -ge "$crit_bio" ]] || \
[[ "$warn_wa" -ge "$crit_wa" ]] ) && \
echo "ERROR: critical levels must be highter than warning levels" && help
# Comparing the result and setting the correct level:
if ( [ "`echo "$bio >= $crit_bio" | bc`" == "1" ] && [ "`echo "$wa >= $crit_wa" | bc`" == "1" ] ); then
msg="CRITICAL"
status=2
else if ( [ "`echo "$bio >= $warn_bio" | bc`" == "1" ] && [ "`echo "$wa >= $warn_wa" | bc`" == "1" ] ); then
msg="WARNING"
status=1
else
msg="OK"
status=0
fi
fi
# Printing the results:
echo "$msg - IO bi/so/wa stats bio=$bio wa=$wa | 'bio'=$bio;$warn_bio;$crit_bio 'wa'=$wa;$warn_wa;$crit_wa"
# Bye!
exit $status