Nagios内存监控脚本
时间:2014-10-26 00:47 来源:linux.it.net.cn 作者:it
Nagios内存监控脚本一例。
复制代码代码如下:
#!/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
#把以上内容复制到/usr/local/nagios/libexec/check_mem.sh
#且使用chmod a+x check_mem.sh 为这个插件添加执行功能
#在command.cfg中添加一项check_mem的内容如下
复制代码代码如下:
# 'check_mem' command definition
define command{
command_name check_mem
command_line $USER1$/check_mem.sh -H $HOSTADDRESS$
}
#在services.cfg中添加内存监控
复制代码代码如下:
define service{
host_name nagios-server
service_description check_mem
check_command check_mem
max_check_attempts 5
normal_check_interval 3
retry_check_interval 2
check_period 24x7
notification_interval 10
notification_period 24x7
notification_options w,u,c,r
contact_groups sagroup
}
测试
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
(责任编辑:IT)
Nagios内存监控脚本一例。
复制代码代码如下:
#!/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
#把以上内容复制到/usr/local/nagios/libexec/check_mem.sh
复制代码代码如下:
# 'check_mem' command definition
define command{ command_name check_mem command_line $USER1$/check_mem.sh -H $HOSTADDRESS$ }
#在services.cfg中添加内存监控
复制代码代码如下:
define service{
host_name nagios-server service_description check_mem check_command check_mem max_check_attempts 5 normal_check_interval 3 retry_check_interval 2 check_period 24x7 notification_interval 10 notification_period 24x7 notification_options w,u,c,r contact_groups sagroup }
测试 |