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

关于nrpe的方式网上已经有很多很好的总结,我现在说说在我们系统中如何是用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. 添加要监控的机器和要监控的服务

2.1  /usr/local/nagios/etc/nagios.cfg: 增加要配置的OBJECT CONFIGURATION FILEs

cfg_file=/usr/local/nagios/etc/objects/localhost.cfg

cfg_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

2. 2添加被监听节点需要被监听的服务,例如:/usr/local/nagios/etc/objects/system_1.cfg

## define hosts
# system_1 oam_1
define host{
        use                     linux-server,host-pnp
        host_name               system_1_oam_1
        address                 <ip>
	contact_groups		system_1_admins,systems_admins
        }
......
# system_1 traffic_1
define host{
        use                     linux-server,host-pnp
        host_name               system_1_traffic_1
        address                 <ip>
	contact_groups		system_1_admins,systems_admins
        }
......
## define services
# system_1 oam_1

define service{
        use                      passive_service,srv-pnp
        service_description      CPU_Status
        host_name                system_1_oam_1
	contact_groups		 system_1_admins,systems_admins
        }
define service{
        use                      passive_service,srv-pnp
        service_description      Memory_Status
        host_name                system_1_oam_1
	contact_groups		 system_1_admins,systems_admins
        }
......

# system_1 traffic_1
define service{
        use                      passive_service,srv-pnp
        service_description      CPU_Status
        host_name                system_1_traffic_1
	contact_groups		 system_1_admins,systems_admins
        }

Note:

host-pnp和srv-pnp是pnp4nagios要用的配置,后面再介绍pnp4nagios的其它配置

3. 对不同的系统添加系统监控管理员

3.1 /usr/local/nagios/etc/objects/contactgroups.cfg

define contactgroup{
        contactgroup_name       system_1_admins
        alias                   system_1_admins
        members                 oam-1,traffic-1
        }
......

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

define contact{
        contact_name                    oam-1                  ; Short name of user
        use                             generic-contact         ; Inherit default values from generic-contact template (defined above)
        alias                           oam-1                  ; Full name of user
        service_notification_options    c
        host_notification_options       d
        email                           [email protected]   ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
        }

define contact{
        contact_name                    traffic-1           ; Short name of user
        use                             generic-contact         ; Inherit default values from generic-contact template (defined above)
        alias                           traffic-1           ; Full name of user
        email                           [email protected]  ; <<***** 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 specify
n (none) as an option, the contact will not receive any type of host notifications.

4. NSCA

如果没有端口冲突之类的问题,直接使用默认配置

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

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-file
       command_line    /bin/mv /usr/local/pnp4nagios/var/service-perfdata /usr/local/pnp4nagios/var/spool/service-perfdata.$TIMET$
}

define command{
       command_name    process-host-perfdata-file
       command_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 monitored Client配置和脚本实现

时间: 2024-12-04 21:40:54

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

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

Nagios要求被监控端按照约定格式定时将数据发送到Nagios端.监控包括节点和服务2种. 节点监控约定数据格式如下: [<timestamp>] PROCESS_HOST_CHECK_RESULT;<host_name>;<host_status>;<plugin_output> 格式很容易理解,数据提交时间戳,被监控节点名称,节点状态(UP/DOWN/UNREARCHABLE),插件自定义的额外数据.状态具体每个字段的解释如下: 1. timestam

Nagios监控Linux系统资源使用情况 -- Nagios介绍篇

应用场景:测试环境以及运行时环境都需要实时监控程序来监控系统(Linux Redhat)的健康状态,监控需求主要集中在:CPU,Memory,Disk IO,Network使用情况 . Nagios的基本思想就是nagios server 获取被监控节点(monitored server)的相关信息,通过CGI(Web GUI)或者邮件等方式展示给管理员. 以前我有介绍过如何通过jmeter+jmeter-plugins来监控系统资源使用情况,有了Nagios之后我们就放弃了使用jmeter,因

监控Linux系统资源使用情况

用于监控linux系统使用情况的shell 参考:https://www.cnblogs.com/yepei/p/7216945.html #!/bin/bash #统一写下接收监控邮件的邮箱 mail_account="[email protected]" #监控系统负载与CPU.内存.硬盘.登录用户数,超出警戒值则发邮件告警. #提取本服务器的IP地址信息 IP=`/sbin/ifconfig eth0 | grep "inet addr" | cut -f 2

Nagios利用NRPE监控Linux主机(3)

一.利用NRPE监控远程Linux的"本地信息" 上面已经对远程Linux 主机是否存活做了监控,而判断远程机器是否存活,我们可以使用ping 工具对其监测.还有一些远程主机服务,例如ftp.ssh.http,都是对外开放的服务,即使不用Nagios,我们也可以试的出来,随便找一台机器看能不能访问这些服务就行了.但是对于像磁盘容量,cpu负载这样的"本地信息",Nagios只能监测自己所在的主机,而对其他的机器则显得有点无能为力.毕竟没得到被控主机的适当权限是不可能

Snmp 方式监控linux服务器

Snmp 方式监控linux服务器 一.  被监控端修改 shell#yum install net-snmp –y shell# mv /etc/snmp/snmpd.conf  /etc/snmp/snmpd.conf.bak shell# vim /etc/snmpd/snmpd.conf com2sec mynetwork 10.0.2.161 public  #这里写服务端的ip,表示允许这台机器访问你的snmp,如果default就是默认全部都可以访问. group MyROGrou

Lr监控linux系统资源方法

1.监控linux系统需要开启rstatd和xinetd两个服务,查看系统是否配置rstatd.xinetd守护进程:   输入命令:rpcinfo -p查看rstatd服务   输入命令:rpm -q xinetd查看xinetd服务 2. 监控linux系统需要安装下载4个服务包:(1)rpc.rstatd-4.0.1.tar.gz(2)rsh-0.17-14.i386.rpm (3)rsh-server-0.17-14.i386.rpm (4)xinetd-2.3.14-10.el5.i3

Nagios利用NRPE监控Linux主机

一.简介 1.NRPE介绍 NRPE是Nagios的一个功能扩展,它可在远程Linux/Unix主机上执行插件程序.通过在远程服务器上安装NRPE插件及Nagios插件程序来向Nagios监控平台提供该服务器的本地情况,如CPU负载,内存使用,磁盘使用等.这里将Nagios监控端称为Nagios服务器端,而将远程被监控的主机称为Nagios客户端. Nagios监控远程主机的方法有多种,其方式包括SNMP,NRPE,SSH,NCSA等.这里介绍其通过NRPE监控远程Linux主机的方式. NRP

LoadRunner如何监控Linux系统资源

一 简述:LoadRunner监控Linux资源时弹出如下错误: Monitor name :UNIX Resources. Cannot initialize the monitoring on 192.168.52.189. Error while creating the RPC client. Ensure that the machine can be connected and that it runs the rstat daemon (use rpcinfo utility fo

nagios通过check_traffic监控Linux,windows主机网卡流量

一,被监控端-Linux 1.安装snmp yum install net-snmp* 2.配置snmp [[email protected] ~]#grep -v "^#" /etc/snmp/snmpd.conf |grep -v "^$" com2sec notConfigUser  default       public com2sec notConfigUser  192.168.80.132       public group   notConfig