with 发表于 2013-6-18 09:01:36

为nagios编写检查Mem脚本

# pwd
/wxl/nagios/libexec# ll check_mem.sh
-rwxr-xr-x 1 nagios nagios 370 May 29 14:39 check_mem.sh所属主及组都是nagios# cat check_mem.sh
#!/bin/bash
# check memory script
# wuxinglai 2013-05-29
# Total memory
TOTAL=`free -m | head -2 |tail -1 |gawk '{print $2}'`
# Free memory
FREE=`free -m | head -2 |tail -1 |gawk '{print $4}'`
# to calculate free percent
# use the expressionfree * 100 / total
FREETMP=`expr $FREE \* 100`
PERCENT=`expr $FREETMP / $TOTAL`
echo "$FREE MB ($PERCENT%) Free Memory"
exit 0
#在/wxl/nagios/etc/objects/commands.cfg里添加一下配置
#'check_mem' command definition
definecommand{
       command_name    check_mem
       command_line    $USER1$/check_mem.sh -H $HOSTADDRESS$
}在service.cfg 定义文件
define service{
       use                           local-service         ; Name of service template to use
       host_name                         server01
       service_description             Current Mem
       check_command                   check_mem
      }重启服务即可

帅帅男孩 发表于 2013-6-18 09:11:45

自从我变成了狗屎,就再也没有人踩在我头上了。

gdx 发表于 2013-6-18 10:28:27

写的真的很不错

mwjhw216 发表于 2013-6-18 11:05:12

看尽天下A片,心中自然无码~

a2005147 发表于 2013-6-18 12:00:45

走过了年少,脚起了水泡

k668 发表于 2013-6-18 13:09:09

关羽五绺长髯,风度翩翩,手提青龙偃月刀,江湖人送绰号——刀郎。

xiaowei8782088 发表于 2013-6-18 13:29:31

我在马路边丢了一分钱
页: [1]
查看完整版本: 为nagios编写检查Mem脚本