您当前的位置: 首页 > 学无止境 > 心得笔记 网站首页心得笔记
企业级监控系列之六——nagios高级应用及插件开发
发布时间:2019-08-04 16:32:14编辑:雪饮阅读()
nagios实现windows的监控
客户端安装
安装"NSClient.-0.3.8-Win32.msi"
放行监控端
启动服务
服务端监控测试
监控机器启动至今的时间
[root@localhost ~]# /usr/local/nagios/libexec/check_nt -H 192.168.2.177 -p 12489 -v UPTIME
System Uptime - 0 day(s) 0 hour(s) 11 minute(s)
监控机器的监控cpu负载
[root@localhost ~]# /usr/local/nagios/libexec/check_nt -H 192.168.2.177 -p 12489 -v CPULOAD -w 80 -c 90 -l 5,80,90
CPU Load 0% (5 min average) | '5 min avg Load'=0%;80;90;0;100
-w:警告比例
-c:紧急比例
-l:过去5分钟平均负载
警告,紧急
输出信息中“|”之前的 是一般信息,之后的 是性能信息
监控机器的磁盘使用率
-l:指定盘符
[root@localhost ~]# /usr/local/nagios/libexec/check_nt -H 192.168.2.177 -p 12489 -v USEDDISKSPACE -w 80 -c 90 -l C
C:\ - total: 39.99 Gb - used: 2.86 Gb (7%) - free 37.13 Gb (93%) | 'C:\ Used Space'=2.86Gb;31.99;35.99;0.00;39.99
服务端配置
配置/etc/nagios/objects/windows.cfg:
将" define host"段中的address,配置为192.168.2.177(windows被监控主机地址)
配置/etc/nagios/nagios.cfg
在" cfg_file=/etc/nagios/objects/templates.cfg"行之下
追加" cfg_file=/etc/nagios/objects/windows.cfg "
测试
[root@localhost ~]# service nagios restart
[root@localhost ~]# service httpd restart
nrpe方式监控linux主机(客户端)
用户
useradd -s /sbin/nologin nagios
安装nagios插件
tar -zxvf nagios-plugins-1.4.15.tar.gz
[root@localhost nagios-plugins-1.4.15]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios
[root@localhost nagios-plugins-1.4.15]# make all
[root@localhost nagios-plugins-1.4.15]# make install
安装nrpe
tar -zxvf nrpe-2.12.tar.gz
[root@localhost nrpe-2.12]# ./configure --with-nrpe-user=nagios --with-nrpe-group=nagios --with-nagios-user=nagios --with-nagios-group=nagios --enable-command-args --enable-ssl
[root@localhost nrpe-2.12]# make all
[root@localhost nrpe-2.12]# make install-plugin
[root@localhost nrpe-2.12]# make install-daemon
[root@localhost nrpe-2.12]# make install-daemon-config
配置/usr/local/nagios/etc/nrpe.cfg
放行监控端地址
allowed_hosts=192.168.2.140
配置硬盘检测
找到" command[check_hda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda1"
在其下行新增如:
command[check_sda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda1
command[check_sda2]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda2
然后将" command[check_hda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda1"删除
服务启动
[root@localhost nrpe-2.12]# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
nrpe方式监控linux主机(服务端)
安装nrpe
tar -zxvf nrpe-2.12.tar.gz
[root@localhost nrpe-2.12]# ./configure --with-nrpe-user=nagios --with-nrpe-group=nagios --with-nagios-user=nagios --with-nagios-group=nagios --enable-command-args --enable-ssl
[root@localhost nrpe-2.12]# make all
[root@localhost nrpe-2.12]# make install-plugin
服务端监控linux主机的通信测试
[root@localhost nrpe-2.12]# /usr/local/nagios/libexec/check_nrpe -H 192.168.2.195
NRPE v2.12
配置
/etc/nagios/objects/commands.cfg
增加一段配置如:
define command {
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
这里的USER1是脚本目录路径的宏
/etc/nagios/objects/linhost.cfg(新文件)
define host{
use linux-server
host_name linhost
alias My Linux Server
address 192.168.2.195
}
define service{
use generic-service
host_name linhost
service_description CHECK USERS
check_command check_nrpe!check_users
}
define service{
use generic-service
host_name linhost
service_description Load
check_command check_nrpe!check_load
}
define service{
use generic-service
host_name linhost
service_description SDA1
check_command check_nrpe!check_sda1
}
define service{
use generic-service
host_name linhost
service_description SDA2
check_command check_nrpe!check_sda2
}
define service{
use generic-service
host_name linhost
service_description Zombie
check_command check_nrpe!check_zombie_procs
}
define service{
use generic-service
host_name linhost
service_description Total procs
check_command check_nrpe!check_total_procs
}
/etc/nagios/nagios.cfg
在"cfg_file=/etc/nagios/objects/windows.cfg"所在行下面添加一行如:
cfg_file=/etc/nagios/objects/linhost.cfg
服务
[root@localhost nrpe-2.12]# service nagios restart
nrpe方式监控linux主机(测试)
nagios实现windows的监控(nrpe)
windows客户端配置
在windows中找到NSCLlent++安装目录中nsc配置文件,如
C:\Program Files\NSClient++\NSC.ini
中配置如下参数
allow_arguments=1
allow_nasty_meta_chars=1
use_ssl=1
然后重启服务
dos中如:
C:\Documents and Settings\x>cd C:\Program Files\NSClient++
C:\Program Files\NSClient++>nsclient++.exe /stop
Stopping service.
C:\Program Files\NSClient++>nsclient++.exe /start
Starting NSClientpp
服务器端测试
简单的通信测试
[root@localhost nrpe-2.12]# /usr/local/nagios/libexec/check_nrpe -H 192.168.2.177
I (0.3.8.75 2010-05-27) seem to be doing fine...
cpu负载监控测试
[root@localhost nrpe-2.12]# /usr/local/nagios/libexec/check_nrpe -H 192.168.2.177 -c checkCPU -a warn=80 crit=90 time=20 time=10 time=5
OK CPU Load ok.|'20'=0%;80;90; '10'=1%;80;90; '5'=1%;80;90;
警告比例80,紧急比例90,过去20分钟,过去10分钟,过去5分钟的cpu负载情况
关键字词:nagios,监控