资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

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

#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] [-c|--critical]"

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

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


文章题目:nagios下配置监控系统内存的使用情况的脚本,带预警功能-创新互联
当前地址:http://www.cdkjz.cn/article/igehd.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220