[root@nagios-server libexec]# pwd
/wxl/nagios/libexec
專注于為中小企業(yè)提供網(wǎng)站建設(shè)、成都網(wǎng)站設(shè)計服務(wù),電腦端+手機端+微信端的三站合一,更高效的管理,為中小企業(yè)華州免費做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動了近千家企業(yè)的穩(wěn)健成長,幫助中小企業(yè)通過網(wǎng)站建設(shè)實現(xiàn)規(guī)模擴充和轉(zhuǎn)變。
[root@nagios-server libexec]# ll check_mem.sh
-rwxr-xr-x 1 nagios nagios 370 May 29 14:39 check_mem.sh 所屬主及組都是nagios
[root@nagios-server libexec]# 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 expression free * 100 / total
FREETMP=`expr $FREE \* 100`
PERCENT=`expr $FREETMP / $TOTAL`
echo "$FREE MB ($PERCENT%) Free Memory"
exit 0
[root@nagios-server libexec]#
在/wxl/nagios/etc/objects/commands.cfg里添加一下配置
#'check_mem' command definition
define command{
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
}
重啟服務(wù)即可