nagios监控机IP:192.168.1.141,被监控机:192.168.1.168
监控CPU
前提是在监控机上安装好nagios和nrpe客户端以及被监控端安装nrpe-server
在被监控机,写个脚本放在/usr/local/nagios/libexec并赋予执行权限
[root@localhost libexec]# pwd
/usr/local/nagios/libexec
[root@localhost libexec]# cat check_cpu
#!/bin/bash
a=`uptime | awk 'NR==1{T=$8}END{print T*100}' | cut -d "," -f 1`
if [ $a -gt 300 ];then
echo taigao
exit 2
fi
echo $a
if [ $a -lt 300 ] && [ $a -gt 200 ];then
echo haixing
exit 1
else
echo meiwent
exit 0
fi
define host {
host_name user1
alias test
address 192.168.1.168
check_command check-host-alive
notification_options d,u,r
check_interval 1
max_check_attempts 2
contact_groups admins
notification_interval 10
notification_period 24x7
}
监控内存
首先看下内存信息吧 [root@localhost ~]# free -m total used free shared buffers cached Mem: 249 235 14 0 3 96 -/+ buffers/cache: 134 114 Swap: 2047 43 2003 根据情况取值比如mem_free + cached,也可写成根据百分比判断 保存自定义插件到nagios下的插件目录 /usr/local/nagios/libexec/check_mem 配置/usr/local/nagios/etc/objects/localhost.cfg define host { host_name shenmeh alias server1 address 192.168.1.129 check_command check-host-alive notification_options d,r check_interval 1 max_check_attempts 2 contact_groups admins notification_interval 1 notification_period 24x7 } define service { host_name shenmeh service_description server1_apache_mem check_period 24x7 normal_check_interval 2 retry_check_interval 1 max_check_attempts 2 notification_period 24x7 notification_options w,u,c,r check_command check_mem }