在被监控机
1./usr/local/nagios/libexec/ 下添加check_mem
内容如下
#!/bin/bash
# check memory script
# sunny 2008.2.15
# 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
2. chmod a+x check_mem.sh
3.vi /usr/local/nagios/etc/nrpe.cfg 增加command
command[check_mem]=/usr/lib64/nagios/plugins/check_mem.sh -w 10 -c 5
nagios 服务端
1.在command.cfg添加如下 (这一步好像也可以不用)
# 'check_mem' command definition
define command{
command_name check_mem
command_line $USER1$/check_mem -H $HOSTADDRESS$
}
2.修改linux客户机配置文件,添加
define service{
use generic-service
host_name mylinux
service_description check_mem
check_command check_nrpe!check_mem
}
3.验证配置: nagios -v /etc/nagios/nagios.cfg
4.重启nagios :service nagios restart
5.登录查看web监控