利用nrpe通過nagios插件check_load監(jiān)控主機(jī)的cpu使用情況
聯(lián)系人及聯(lián)系方式,發(fā)郵件等都已設(shè)置好,這里不再敘述。
1、在被監(jiān)控主機(jī)上安裝nrpe服務(wù)器,然后把nagios的所有插件都cp到nrpe的安裝目錄下,打開nrpe的配置文件nrpe.cfg,根據(jù)實(shí)際情況修改check_load插件的監(jiān)控閥值。
command[check_load]=/usr/local/nagios/libexec/check_load -w 4,3,3 -c 6,4,3
2、在nagios端配置監(jiān)控主機(jī)和服務(wù),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、自己編寫插件,監(jiān)控cpu
在被監(jiān)控主機(jī)/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文件中定義監(jiān)控服務(wù)
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、結(jié)果截圖
用ab 命令給對(duì)被監(jiān)控主機(jī)壓力測(cè)試,加重cpu的負(fù)載,使其實(shí)現(xiàn)報(bào)警
網(wǎng)站題目:nagios監(jiān)控遠(yuǎn)程主機(jī)上的資源-cpu
轉(zhuǎn)載注明:
http://weahome.cn/article/isgiid.html