利用nrpe通過nagios插件check_load監控主機的cpu使用情況
聯繫人及聯繫方式,發郵件等都已設置好,這裏不再敘述。
1、在被監控主機上安裝nrpe服務器,然後把nagios的所有插件都cp到nrpe的安裝目錄下,打開nrpe的配置文件nrpe.cfg,根據實際情況修改check_load插件的監控閥值。
command[check_load]=/usr/local/nagios/libexec/check_load -w 4,3,3 -c 6,4,3
2、在nagios端配置監控主機和服務,localhost.cfg文件
define host {
host_name Mmysql
alias master
address 10.1.1.2
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
}
define service {
host_name Mmysql
service_description cpu
check_period 24x7
normal_check_interval 1
retry_check_interval 1
max_check_attempts 3
notification_period 24x7
notification_options w,u,c,r
check_command check_nrpe!check_load
}
配置commands.cfg
define command {
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
3、重新載入nagios ,
4、自己編寫插件,監控cpu
在被監控主機/usr/local/nagios/libexec 下編寫check_cpu shell腳本。
#!/bin/bash
cpu=`uptime|awk '{print $9}'|sed -rn 's/(.*)\..*/\1/p'`
if [ $cpu -gt 3 ];then
echo fuck!!! the cup is died
exit 2
else
echo Good the cup is ok
exit 0
fi
5、在nrpe的配置文件nrpe.cfg文件中定義新建的插件命令
command[check_cpu]=/usr/local/nagios/libexec/check_cpu
6、在nagios端的localhost.cfg文件中定義監控服務
define service {
host_name Mmysql
service_description cpu_01
check_period 24x7
normal_check_interval 1
retry_check_interval 1
max_check_attempts 3
notification_period 24x7
notification_options w,u,c,r
check_command check_cpu!check_cpu
}
7、在commands.cfg文件中定義命令
define command {
command_name check_cpu
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
8、重新載入nagios
9、結果截圖
用ab 命令給對被監控主機壓力測試,加重cpu的負載,使其實現報警