温馨提示×

温馨提示×

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

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

nagios中check_memory插件怎么用

发布时间:2021-11-23 09:58:17 来源:亿速云 阅读:215 作者:小新 栏目:移动开发

这篇文章将为大家详细讲解有关nagios中check_memory插件怎么用,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

#!/bin/bash #describe:nagios  check_memory #return:0:OK|1:waring|2:critical|3:unknown #Usage:-w(waring) -c(cirtical) -u(KB|MB|GB|TB) -h(--help) -v(--version) WARING= CIRTICAL= UNIT= VERSION='1.0.1' declare -A UNIT_MAP UNIT_MAP=([KB]=0 [MB]=1 [GB]=2 [TB]=3) UNIT_MIX=1024 help=no version=no for option do   case "$option" in      -*=*) value=`echo $option|sed 's/[-a-zA-Z0-9]*=//'` ;;      *) value="" ;;   esac   case "$option" in     -h) help=yes ;;     --help) help=yes ;;     -v) version=yes ;;     -w=*) WARING="$value" ;;     -c=*) CIRTICAL="$value" ;;     -u=*) UNIT="$value" ;;     *)     echo "$0: error: invalid option \"$option\""     exit 3     ;;   esac done if [ $help = yes ];then    cat << END        check_memory [option] [value]             nagios check memory             Support the percentage comparison, does not support equivalence comparison        --help              print this message        -h                  print this message        -v                  print this version        -w                  set waring value        -c                  set cirtical value        -u                  set the display unit END    exit 0 fi if [ $version = yes ];then    echo "Copyright: check_memory/$VERSION"    exit 0 fi WARING=${WARING:-'20'} CIRTICAL=${CIRTICAL:-'10'} UNIT=${UNIT:-'MB'} if [ -z ${UNIT_MAP[$UNIT]} ];then    UNIT='MB' fi UNIT_DIV=$(($UNIT_MIX**${UNIT_MAP[$UNIT]})) total=$(free |awk '/Mem/{print $2}') free_avg=$(free -s1 -c5|grep "+"|awk 'BEGIN{free=0}{free+=$4}END{printf("%.0f",free/5)}') precent=`echo "scale=0;"$free_avg \* 100 / $total |bc` free_avg=`echo "scale=2;"$free_avg / $UNIT_DIV |bc` total=`echo "scale=2;"$total / $UNIT_DIV |bc` if test $precent -le $CIRTICAL;then    echo "cirtical,total:$total$UNIT,free space:$free_avg$UNIT,precent:$precent%"    exit 2 fi if test $precent -le $WARING;then    echo "waring,total:$total$UNIT,free space:$free_avg$UNIT,precent:$precent%"    exit 1 fi echo "free ok,total:$total$UNIT,free space:$free_avg$UNIT,precent:$precent%" exit 0

关于“nagios中check_memory插件怎么用”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。

向AI问一下细节

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

AI