aini 发表于 2019-1-15 06:45:14

nagios监控远程主机上的资源

    利用nrpe通过nagios插件check_load监控主机的cpu使用情况
联系人及联系方式,发邮件等都已设置好,这里不再叙述。
1、在被监控主机上安装nrpe服务器,然后把nagios的所有插件都cp到nrpe的安装目录下,打开nrpe的配置文件nrpe.cfg,根据实际情况修改check_load插件的监控阀值。
command=/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_interval1
      max_check_attempts      2
      contact_groupsadmins
      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_cpushell脚本。
#!/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=/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、结果截图
http://blog.运维网.com/jingxiaoliang/../attachment/201303/221111270.jpg
用ab 命令给对被监控主机压力测试,加重cpu的负载,使其实现报警
http://blog.运维网.com/jingxiaoliang/../attachment/201303/221132304.jpg




http://blog.运维网.com/jingxiaoliang/../attachment/201303/221153127.jpg



页: [1]
查看完整版本: nagios监控远程主机上的资源