监控IO瓶颈

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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值