现在说说在我们系统中如何是用NSCA方式来获取我们需要的被监控节点的资源使用情况信息。

先讲讲Nagios Server端的基本配置:

1. nagios web gui 访问配置,系统中使用的是nagios core中推荐的配置方式,通过apache httpd访问nagios web,安装nagios的时候会自动寻找系统中安装的httpd,把nagios的httpd文件放到httpd的conf.d目录下,这样,只要生成一次nagios web访问的密码就可以通过http://localhost/nagios/访问nagios web.
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

2. 在Nagios中定义要监控的机器和要监控的服务

2. 1 在/usr/local/nagios/etc/objects/中定义被监听节点和需要被监听的服务,例如:/usr/local/nagios/etc/objects/system_1.cfg

## define hosts
# system_1 oam_1
define host{use                     linux-server,host-pnphost_name               system_1_oam_1address                 <ip>contact_groups     system_1_admins,systems_admins}
......
# system_1 traffic_1
define host{use                     linux-server,host-pnphost_name               system_1_traffic_1address                 <ip>contact_groups     system_1_admins,systems_admins}
......
## define services
# system_1 oam_1define service{use                      passive_service,srv-pnpservice_description      CPU_Statushost_name                system_1_oam_1contact_groups         system_1_admins,systems_admins}
define service{use                      passive_service,srv-pnpservice_description      Memory_Statushost_name                system_1_oam_1contact_groups       system_1_admins,systems_admins}
......# system_1 traffic_1
define service{use                      passive_service,srv-pnpservice_description      CPU_Statushost_name                system_1_traffic_1contact_groups      system_1_admins,systems_admins}
Note:
a. passive_service是NSCA需要的配置,细节可参考章节4
b. host-pnp和srv-pnp是pnp4nagios要用的配置,细节可参考章节6

2.2  把定义的配置文件添加到/usr/local/nagios/etc/nagios.cfg中

cfg_file=/usr/local/nagios/etc/objects/localhost.cfgcfg_file=/usr/local/nagios/etc/objects/system_1.cfg
cfg_file=/usr/local/nagios/etc/objects/system_2.cfg 
......
nagios_user=nagios
nagios_group=nagios
lock_file=/usr/local/nagios/var/nagios.lock
status_update_interval=10

3. 对不同的系统添加系统监控管理员
3.1 /usr/local/nagios/etc/objects/contactgroups.cfg

define contactgroup{contactgroup_name       system_1_adminsalias                   system_1_adminsmembers                 oam-1,traffic-1}
......

3.2 /usr/local/nagios/etc/objects/contacts.cfg

define contact{contact_name                    oam-1                  ; Short name of useruse                             generic-contact         ; Inherit default values from generic-contact template (defined above)alias                           oam-1                  ; Full name of userservice_notification_options    c                      host_notification_options       demail                           nobody@localhost.com   ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******}define contact{contact_name                    traffic-1           ; Short name of useruse                             generic-contact         ; Inherit default values from generic-contact template (defined above)alias                           traffic-1           ; Full name of useremail                           nobody@localhost.com  ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******}
......

Note:
service_notification_options: This directive is used to define the service states for which notifications can be sent out to this contact. Valid options are a combination of one or more of the following: w = notify on WARNING service states, u = notify on UNKNOWN service states, c = notify on CRITICAL service states, r = notify on service recoveries (OK states), and f = notify when the service starts and stopsflapping. If you specify n (none) as an option, the contact will not receive any type of service notifications.
host_notification_options:This directive is used to define the host states for which notifications can be sent out to this contact. Valid options are a combination of one or more of the following:d = notify on DOWN host states,u = notify on UNREACHABLE host states,r = notify on host recoveries (UP states),f = notify when the host starts and stopsflapping, ands = send notifications when host or servicescheduled downtime starts and ends. If you specifyn (none) as an option, the contact will not receive any type of host notifications.
4. NSCA配置

4.1 NSCA端:如果没有端口冲突之类的问题,/usr/local/nagios/etc/nsca.cfg可以作为默认配置直接使用
Note: 当Nagios端有问题的时候,nsca本身可以保存收到的数据,要小心数据量大小的问题,监控机器多的时候,Nagios挂的时间长了点,文件就很容易变的很大
4.2 Nagios端:
4.2.1 修改/usr/local/nagios/etc/objects/templates.cfg,增加被动检测模版

define service{use                             generic-servicename                            passive_serviceactive_checks_enabled           0passive_checks_enabled          1                       # We want only passive checkingflap_detection_enabled          0register                        0                       # This is a template, not a real serviceis_volatile                     0check_period                    24x7max_check_attempts              1normal_check_interval           5retry_check_interval            1check_freshness                 0contact_groups                  system_adminscheck_command                   check_dummy!0notification_interval           120notification_period             24x7notification_options            w,u,c,rstalking_options                w,c,u}

4. 2.2 修改/usr/local/nagios/etc/commands.cfg,增加命令定义如何处理NSCA发送来的数据

# 'check_nsca' command definition
define command{command_name    check_dummycommand_line    $USER1$check_dummy$ARG1$}

Note: check_dummy很简单,处理Nagios中OK,WARNING,CRITICAL,UNKNOWN

<span style="font-size:10px;">nagios:/usr/local/nagios/etc # /usr/local/nagios/libexec/check_dummy  0
OK
nagios:/usr/local/nagios/etc # /usr/local/nagios/libexec/check_dummy  1
WARNING
nagios:/usr/local/nagios/etc # /usr/local/nagios/libexec/check_dummy  2
CRITICAL
nagios:/usr/local/nagios/etc # /usr/local/nagios/libexec/check_dummy  3
UNKNOWN</span>

4.2.3 检查/usr/local/nagios/etc/nagios.cfg已经可以处理外部NSCA发送来的数据,默认是没有问题的

accept_passive_service_checks=1
<div><pre style="color: rgb(0, 0, 0); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;font-size:14px;">accept_passive_host_checks=1
<div><pre style="color: rgb(0, 0, 0); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;font-size:14px;">check_external_commands=1
command_check_interval=-1
command_file=/usr/local/nagios/var/rw/nagios.cmd
<div><pre style="color: rgb(0, 0, 0); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;font-size:14px;"><em>log_passive_checks=1
</em>

5. 查看Nagios GUI中新加的host和service已经存在

6. 添加pnp4nagios bulk+npcd 模式监听系统

6.1 修改/usr/local/nagios/etc/nagios.cfg

#处理performance数据
process_performance_data=1
#host_perfdata_command=process-host-perfdata
#service_perfdata_command=process-service-perfdata
#performance数据存储文件
host_perfdata_file=/usr/local/pnp4nagios/var/host-perfdata
service_perfdata_file=/usr/local/pnp4nagios/var/service-perfdata
#performance数据存储格式
host_perfdata_file_template=DATATYPE::HOSTPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tHOSTPERFDATA::$HOSTPERFDATA$\tHOSTCHECKCOMMAND::$HOSTCHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$
service_perfdata_file_template=DATATYPE::SERVICEPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tSERVICEDESC::$SERVICEDESC$\tSERVICEPERFDATA::$SERVICEPERFDATA$\tSERVICECHECKCOMMAND::$SERVICECHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$\tSERVICESTATE::$SERVICESTATE$\tSERVICESTATETYPE::$SERVICESTATETYPE$\tSERVICEOUTPUT::$SERVICEOUTPUT$
#performance文件存储方式
host_perfdata_file_mode=a
service_perfdata_file_mode=a
#performance文件处理时间间隔
host_perfdata_file_processing_interval=15
service_perfdata_file_processing_interval=15
<pre name="code" class="plain">#performance文件处理命令

host_perfdata_file_processing_command=process-host-perfdata-fileservice_perfdata_file_processing_command=process-service-perfdata-file 6.2 修改/usr/local/nagios/etc/objects/commands.cfg,增加performance文件处理命令

define command{command_name    process-service-perfdata-filecommand_line    /bin/mv /usr/local/pnp4nagios/var/service-perfdata /usr/local/pnp4nagios/var/spool/service-perfdata.$TIMET$
}define command{command_name    process-host-perfdata-filecommand_line    /bin/mv /usr/local/pnp4nagios/var/host-perfdata /usr/local/pnp4nagios/var/spool/host-perfdata.$TIMET$
}

6.3 修改nagios.cfg,设置在nagios web gui中显示pnp4nagios图标的方式

第一种方法在templates.cfg里面加入如下,只能在新窗口打开图像数据

define host { name       host-pnp action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=_HOST_ register   0
}define service { name       srv-pnp action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$ register   0
}

第二种方法可以在鼠标移到pnp4nagios图标的时候就可以开到实时图标,不过效果不是很好,按照说明加入如下:

拷贝status-header.ssi到/usr/local/nagios/share/ssi/目录下面,同时修改templates.cfg,加入如下内容:

define host { name       host-pnp action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=_HOST_' class='tips' rel='/pnp4nagios/index.php/popup?host=$HOSTNAME$&srv=_HOST_ register   0
}define service { name       srv-pnp action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$' class='tips' rel='/pnp4nagios/index.php/popup?host=$HOSTNAME$&srv=$SERVICEDESC$ register   0
} 

Note: 自动出现的小窗口清晰度不好,我喜欢第一种方式

Note: 这里没有涉及email的配置,记得通知设计的时候小心消息泛滥被投诉。。。

第一篇: Nagios 使用介绍

第三篇: Nagios配置篇 -- 被监控端

实战Nagios NSCA方式监控Linux系统资源使用情况 -- Nagios配置篇 -- Nagios Server端相关推荐

  1. 实战Nagios NSCA方式监控Linux系统资源使用情况 -- Nagios配置篇 -- 被监控端

    Nagios要求被监控端按照约定格式定时将数据发送到Nagios端.监控包括节点和服务2种. 节点监控约定数据格式如下: [<timestamp>] PROCESS_HOST_CHECK_ ...

  2. 【转】[原创]LoadRunner如何监控Linux系统资源

    [原创]LoadRunner如何监控Linux系统资源 http://www.cnblogs.com/mayingbao/archive/2006/06/19/429187.html 一简述:Load ...

  3. linux atop日志查看,A - atop - 监控Linux系统资源与进程的工具 - 《Linux命令大全搜索工具(旧版)》 - 书栈网 · BookStack...

    atop 监控Linux系统资源与进程的工具 补充说明 [非内部程序,需要安装]它以一定的频率记录系统的运行状态,所采集的数据包含系统资源(CPU.内存.磁盘和网络)使用情况和进程运行情况,并能以日志 ...

  4. 监控linux资源的软件,6个监控linux系统资源的快速工具

    系统管理员需要对服务器进行监控以确保其正常运行,通过这种方式管理员能够提前发现可能存在的问题并恢复系统,以避免麻烦的出现. Linux上有很多命令来监控不同的系统资源,如CPU使用率.内存使用情况.网 ...

  5. lr如何监控linux,LoadRunner如何监控Linux系统资源

    一 简述:LoadRunner监控Linux资源时弹出如下错误: Monitor name :UNIX Resources. Cannot initialize the monitoring on 1 ...

  6. Loadrunner如何监控Linux系统资源

    2019独角兽企业重金招聘Python工程师标准>>> Linux 查看连接数: netstat -tn | grep 126 | awk '/^tcp/{++state[$NF]} ...

  7. HostMonitor安裝RMA for Linux监控Linux系统资源

    HostMonitor使用Remote Monitoring Agents(RMA)功能可以监控远端系统资源,在这里只说明Windows版的HostMonitor要能 够监控远端Linux系统资源,必 ...

  8. linux系统下监控录像软件,Linux系统资源监控-Linux系统资源监控工具(LinuxSysMonitor)下载-西西软件下载...

    Linux系统资源监控工具(LinuxSysMonitor),吾爱大神原创制作的一个Linux系统资源监控工具,整合了多套命令系统,用户需要在JDK环境下调用该工具才能顺利运行,可以查看磁盘速度,CP ...

  9. Linux监控利器nagios–NSCA被动监控

    原文地址:http://www.cszhi.com/20120527/nagios-nsca.html

最新文章

  1. oracle+linux+oel+6.9,用SecureCRT+Xming轻松远程实现linux的X DISPLAY
  2. Android 动画分析学习笔记
  3. VC++简单实现工具软件随鼠标移动画线的功能
  4. beego 文件服务器,beego自动化文档
  5. quartz CronExpression表达式
  6. mysql 优化配置 大批量数据插入_MYSQL开发性能研究——批量插入的优化措施
  7. mysql varchar 长度限制_MySQL数据库varchar的限制规则说明
  8. autoscan、aclocal、automake和autoconf区别
  9. js方法点击复制文本
  10. sql如何在两张表中得到每组数据,并知道数据的个数,举例,判断有多少班级,每个班的人数
  11. Redis 对象系统
  12. Microsemi Libero使用技巧3——使用FlashPro单独下载程序
  13. IE插件在注册表中的相关位置
  14. 软件质量属性:可用性
  15. java创建窗口_java如何创建一个窗口出来
  16. css关键词:inherit、initial、overlay、revert、unset解释
  17. java解一元一次方程
  18. 【自然框架】元数据的数据库结构的详细说明和示例(二):数据库描述部分...
  19. mysql dba日常_DBA日常工作职责总结
  20. 扒一扒数据黑色产业链:猖獗内鬼、黑客联盟,你中招了吗?

热门文章

  1. Python的异步编程介绍(MD)
  2. [Spark好友推荐]
  3. 空间曲面构造及其方程
  4. mysql spj_MySQL查询优化器--非SPJ优化--LIMIT优化
  5. this is a prerequisite condition to test whether the packagecompat-libstdc++-33-3.2.3-61.x86_64
  6. sql server使用DAC连接查询系统表
  7. 动态规划 最长不下降子序列
  8. [KDD 2022]ROLAND Graph Learning Framework for Dynamic Graphs
  9. 第八届“图灵杯”NEUQ—ACM程序设计竞赛个人赛(同步赛)
  10. LINUX学习基础篇(六)帮助命令