温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

nagios插件监控cpu,可pnp画图

发布时间:2020-08-13 09:52:16 来源:网络 阅读:883 作者:bensonzy 栏目:移动开发

   check_cpu 是依据从exchange.nagios.org 的脚本修改的。使用原始脚本结构,函数名称、参数也没怎么变化,有看到的,勿拍砖。


#!/bin/bash


ST_OK=0

ST_WR=1

ST_CR=2

ST_UK=3


PROGNAME=`basename $0`


warning=$2

critical=$4

process=$6



get_wcdiff() {

   if [ ! -z "$warning" -a ! -z "$critical" ]

   then

       wclvls=1

       if [ ${warning} -gt ${critical} ]

       then

           wcdiff=1

       fi

   elif [ ! -z "$warning" -a -z "$critical" ]

   then

       wcdiff=2

   elif [ -z "$warning" -a ! -z "$critical" ]

   then

       wcdiff=3

   fi

}


val_wcdiff() {

   if [ "$wcdiff" = 1 ]

   then

       echo "Please adjust your warning/critical thresholds. The warning must be lower than the critical level!"

       exit $ST_UK

   elif [ "$wcdiff" = 2 ]

   then

       echo "Please also set a critical value when you want to use warning/critical thresholds!"

       exit $ST_UK

   elif [ "$wcdiff" = 3 ]

   then

       echo "Please also set a warning value when you want to use warning/critical thresholds!"

       exit $ST_UK

   fi

}


get_vals() {


   tmp_output=$(top -n 1 -b | grep $process )


   top_cpu=$(echo ${tmp_output} | awk '{print $9}')


   int_cpu=$(echo ${top_cpu%.*})


}


do_perfdata() {

perfdata="cpu=${top_cpu}%"

}



get_wcdiff

val_wcdiff

get_vals

do_perfdata


if [ -n "$warning" -a -n "$critical" ]

then

   if [ "$int_cpu" -ge "$warning" -a "$int_cpu" -lt "$critical" ]

   then

       echo "WARNING - ${perfdata} | ${perfdata}"

exit $ST_WR

   elif [ "$int_cpu" -ge "$critical" ]

   then

       echo "CRITICAL - ${perfdata} | ${perfdata}"

exit $ST_CR

   else

       echo "OK - ${perfdata} | ${perfdata} "

exit $ST_OK

   fi

else

   echo "Usage Example: $PROGNAME -w 3 -c 12 -p firefox "

   exit $ST_OK

fi


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI