check_mem_sio脚本内容如下:
#!/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此功能为检测主机内存是否达到瓶颈,检测参数为si和so。\n\t一般情况si、so长期为0。如果si、so长期不为0,则表示系统内存不足\n\t-w <si警告阈值>,<si警告阈值> \n\t-c <si critical阈值>,<si 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_si=`echo $critical | cut -d, -f1`
crit_so=`echo $critical | cut -d, -f2`
warn_si=`echo $warning | cut -d, -f1`
warn_so=`echo $warning | cut -d, -f2`
# Doing the actual check:
si=`$vmstat 1 2| tail -1 | awk '{print $7}'`
so=`$vmstat 1 2| tail -1 | awk '{print $8}'`
# Checking parameters:
( [[ "$warn_si" -ge "$crit_si" ]] || \
[[ "$warn_so" -ge "$crit_so" ]] ) && \
echo "ERROR: critical levels must be highter than warning levels" && help
# Comparing the result and setting the correct level:
if ( [ "`echo "$si >= $crit_si" | bc`" == "1" ] || [ "`echo "$so >= $crit_so" | bc`" == "1" ] ); then
msg="CRITICAL"
status=2
else if ( [ "`echo "$si >= $warn_si" | bc`" == "1" ] || [ "`echo "$so >= $warn_so" | bc`" == "1" ] ); then
msg="WARNING"
status=1
else
msg="OK"
status=0
fi
fi
# Printing the results:
echo "$msg - mem si/so stats si=$si so=$so | 'si'=$si;$warn_si;$crit_si 'so'=$so;$warn_so;$crit_so"
# 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此功能为检测主机内存是否达到瓶颈,检测参数为si和so。\n\t一般情况si、so长期为0。如果si、so长期不为0,则表示系统内存不足\n\t-w <si警告阈值>,<si警告阈值> \n\t-c <si critical阈值>,<si 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_si=`echo $critical | cut -d, -f1`
crit_so=`echo $critical | cut -d, -f2`
warn_si=`echo $warning | cut -d, -f1`
warn_so=`echo $warning | cut -d, -f2`
# Doing the actual check:
si=`$vmstat 1 2| tail -1 | awk '{print $7}'`
so=`$vmstat 1 2| tail -1 | awk '{print $8}'`
# Checking parameters:
( [[ "$warn_si" -ge "$crit_si" ]] || \
[[ "$warn_so" -ge "$crit_so" ]] ) && \
echo "ERROR: critical levels must be highter than warning levels" && help
# Comparing the result and setting the correct level:
if ( [ "`echo "$si >= $crit_si" | bc`" == "1" ] || [ "`echo "$so >= $crit_so" | bc`" == "1" ] ); then
msg="CRITICAL"
status=2
else if ( [ "`echo "$si >= $warn_si" | bc`" == "1" ] || [ "`echo "$so >= $warn_so" | bc`" == "1" ] ); then
msg="WARNING"
status=1
else
msg="OK"
status=0
fi
fi
# Printing the results:
echo "$msg - mem si/so stats si=$si so=$so | 'si'=$si;$warn_si;$crit_si 'so'=$so;$warn_so;$crit_so"
# Bye!
exit $status