nagios之passive_check
来自:网络
[ /u/877567/blog/325881#OSC_h2_1]title: “nagios/passive_check”[ /u/877567/blog/325881#OSC_h2_2]术语[ /u/877567/blog/325881#OSC_h2_3]被动模式工作原理:[ /u/877567/blog/325881#OSC_h2_4]原理图[ /u/877567/blog/325881#OSC_h2_5]优缺点[ /u/877567/blog/325881#OSC_h2_6]nagios 配置[ /u/877567/blog/325881#OSC_h2_7]被动检测提交的格式:[ /u/877567/blog/325881#OSC_h2_8]通过外部命令文件提交结果[ /u/877567/blog/325881#OSC_h2_9]nrdp 的提交方式[ /u/877567/blog/325881#OSC_h2_10]通过mod_gearman提交结果[ /u/877567/blog/325881#OSC_h2_11]参考
layout: post
title: “nagios/passive_check”术语 nagios培训
- 被监控机(MC:Monitor Client)
- 监控机 (MS:Monitor Server)
- nsca 插件采用的是将检测结果写入外部命令文件,该文件是一个管道文件,也是nagios主程序的一个接口(用来接收监控数据),(ubuntu14.04 nagios 默认配置是 “/var/lib/nagios3/rw/nagios.cmd”);
- nrdp 插件除了将检测结果写入外部命令文件,还可以将检测结果直接写入到Nagios内核的spool目录,(ubuntu14.04 nagios 默认配置是 “/var/lib/nagios3/spool/checkresults”);
- mod_gearman 使用事件代理模式,会将结果注入nagios结果环形缓冲区数据结构中,不会被FIFO的IO限制
优缺点优点:相比与主动模式,被动模式能很大程度地降低nagios负载
缺点:当监控的主机规模进一步扩大,会被"外部命令文件"I/O局限所拖累,(事件代理模式除外) nagios 配置注意:(本文是ubuntu14.04为基础环境,创建被动模式的配置,以下分别用术语中定义的简称 MS,MC) nagios实施
- 开启被动监控
check_external_commands = 1 (enable commands file) # 允许检测结果写入外部命令文件command_check_interval = -1 (check the external command file as often as possible)
- 定被模板
define service{ name passive_service use generic-service max_check_attempts 1 active_checks_enabled 0 #(关闭主动检测) passive_checks_enabled 1 #(开启被动检测) normal_check_interval 5 retry_check_interval 1 check_freshness 1 # (开启强制刷新) notifications_enabled 1 notification_interval 5 notification_period 24x7 contact_groups admins register 0 #(必须) }
- 定义被动监控指令
define command { command_name check_dummy command_line /usr/lib/nagios/plugins/check_dummy $ARG1$ $ARG2$}check_dummy指令实际上不检查任何东西,指定两个参数,一个是状态,一个是输出,始终返回这两个参数。 监控软件 # /usr/lib/nagios/plugins/check_dummy 0 successfulOK: successful# /usr/lib/nagios/plugins/check_dummy 1 failedWARNING: failed# /usr/lib/nagios/plugins/check_dummy 2 failedCRITICAL: failed# /usr/lib/nagios/plugins/check_dummy 3 failedUNKNOWN: failed
- 定义要被动监控的主机
# echo "[`date +%s`] PROCESS_HOST_CHECK_RESULT;mc_hostname;0;ping is ok" >> /var/lib/nagios3/rw/nagios.cmd# echo "[`date +%s`] PROCESS_SERVICE_CHECK_RESULT;mc_hostname;check_ssh_passive;0;test is ok " >> /var/lib/nagios3/rw/nagios.cmdnrdp 的提交方式外部应用程序可以向 Nagios内核的spool目录写入存放检测结果的文件(ubuntu14.04 nagios 默认配置是 “/var/lib/nagios3/spool/checkresults”):
主机检测结果文件:cpjCd4i ### NRDP Check ###start_time=1415871546.0# Time: Thu, 13 Nov 2014 09:39:06 +0000host_name=cdn-gc- nagios配置 ### NRDP Check ###start_time=1415871546.0# Time: Thu, 13 Nov 2014 09:39:06 +0000host_name=cdn-gc-dongguan1service_description=SSHcheck_type=1early_timeout=1exited_ok=1return_code=1output=WARNING: Danger Will Robinson!|perfdata\n通过mod_gearman提交结果当nagios加载 broker_module=/usr/lib/mod_gearman/mod_gearman.o 后,会在gearman-job-server中创建一个名为check_results 的任务队列,client请求任务,worker 处理后,最终将结果写入check_results 的任务队列,mod_gearman.o 取回结果传递给nagios核心进程,完成一次任务的分发处理。
以python_gearman 编程接口为例,(这货貌似好久没有更新了,也不支持加密传输) 开源监控软件 #!/usr/bin/env pythonimport gearmangm_client = gearman.GearmanClient(['localhost:4730'] )completed_job_request = gm_client.submit_job("check_results", "type=passive host_name=cdn-tx-wuhan-ctc3 core_start_time=1415807730.0 start_time=1415807730.19546 finish_time=1415807730.105364 return_code=2 exited_ok=0 output=PING_OK\n")mod_gearman C源码片断
gearman_util.c 提交结果的主要部分:add_job_to_queue(...) { task = gearman_client_add_task_low_background( client, NULL, NULL, queue, uniq, ( void * )crypted_data, ( size_t )size, &ret1 ); gearman_task_give_workload(task,crypted_data,size);} nagios安装
想做Nagios, Zabbix,Cacti,iTop各种交流的,可以进入开源监控工具Nagios交流 QQ群号 :476809427