nagios下配置监控系统内存的使用情况的脚本,带预警功能

发布时间:2020-07-31 12:07:14 作者:刘舣翔
来源:网络 阅读:618

#script to check real memory usage

# Miracle 2013/12/23 - V.1.0

# ------------------------------------------

# ########  Script Modifications  ##########

# ------------------------------------------

# Who         When           What

# ---    ----      ----

# Miracle         2013/12/23  "$percent" lt 1% fix - sed edits dc result beggining with "."

#

#

#!/bin/bash

USAGE="`basename $0` [-w|--warning]<percent free> [-c|--critical]<percent free>"

THRESHOLD_USAGE="WARNING threshold must be greater than CRITICAL: `basename $0` $*"

calc=/tmp/memcalc

percent_free=/tmp/mempercent

critical=""

warning=""

STATE_OK=0

STATE_WARNING=1

STATE_CRITICAL=2

STATE_UNKNOWN=3

# print usage

if [[ $# -lt 4 ]]

then

       echo ""

       echo "Wrong Syntax: `basename $0` $*"

       echo ""

       echo "Usage: $USAGE"

       echo ""

       exit 0

fi

# read input

while [[ $# -gt 0 ]]

 do

       case "$1" in

              -w|--warning)

              shift

              warning=$1

       ;;

              -c|--critical)

              shift

              critical=$1

       ;;

       esac

       shift

 done


# verify input

if [[ $warning -eq $critical || $warning -lt $critical ]]

then

       echo ""

       echo "$THRESHOLD_USAGE"

       echo ""

       echo "Usage: $USAGE"

       echo ""

       exit 0

fi

# Total memory available

total=`free -m | head -2 |tail -1 |gawk '{print $2}'`

# Total memory used

used=`free -m | head -2 |tail -1 |gawk '{print $3}'`

# Calc total minus used

free=`free -m | head -2 |tail -1 |gawk '{print $4}'`

# normal values

#echo "$total"MB total

#echo "$used"MB used

#echo "$free"MB free

# make it into % percent free = ((free mem / total mem) * 100)

echo "5" > $calc # decimal accuracy

echo "k" >> $calc # commit

echo "100" >> $calc # multiply

echo "$free" >> $calc # division integer

echo "$total" >> $calc # division integer

echo "/" >> $calc # division sign

echo "*" >> $calc # multiplication sign

echo "p" >> $calc # print

percent=`/usr/bin/dc $calc|/bin/sed 's/^\./0./'|/usr/bin/tr "." " "|/usr/bin/gawk {'print $1'}`

#percent1=`/usr/bin/dc $calc`

#echo "$percent1"

if [[ "$percent" -le  $critical ]]

       then

               echo "CRITICAL - $free MB ($percent%) Free Memory"

               exit 2

fi

if [[ "$percent" -le  $warning ]]

       then

               echo "WARNING - $free MB ($percent%) Free Memory"

               exit 1

fi

if [[ "$percent" -gt  $warning ]]

       then

               echo "OK - $free MB ($percent%) Free Memory"

               exit 0

fi





推荐阅读:
  1. NAGIOS监控系统
  2. nagios自定义监控系统磁盘脚本

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

nagios memory result

上一篇:用JS实现的俄罗斯方块

下一篇:Mydumper安装报错处理

相关阅读

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

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