监控内存瓶颈

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值