Nagios check_logfiles插件的使用记录

1 获取与安装

https://labs.consol.de/assets/downloads/nagios/check_logfiles-3.7.4.tar.gz

链接可能会失效,建议去官网下载。

https://labs.consol.de/nagios/check_logfiles/

阅读官网的使用说明,但感觉还是不太明了,毕竟是英文 的,

http://blog.chinaunix.net/uid-261392-id-2138989.html

这是开源中国上面一兄弟写的介绍,让你入门。

tar xvf check_logfiles-3.7.4.tar.gz

./configure

make && make install

安装完成。

安装的时候使用的是root用户,安装后其实是在libexec下多了一个check_logfiles程序。

建议把该程序的owner改为nagios.nagiios.其实不改也可以,它的权限是其他组也可以执行。

chown nagios:nagios /usr/local/nagios/libexec/check_logfiles

2 我以在某节点dn42上监控datanode与nodemanager进程的日志为目标,做了一下处理

a. nagios目录/usr/local/nagios/下创建var/tmp目录,如果没有,并且权限要给nagios.nagios.

因为我们需要配置check_logfiles来存储状态文件和一些信息在这个目录里面。编译时未指定,它的默认目录可能没有访问权限。

b.创建配置文件,我放在/usr/local/nagios/etc/log.cfg

配置如下:

$seekfilesdir = '/usr/local/nagios/var/tmp';
$protocolsdir = '/usr/local/nagios/var/tmp';
$scriptpath = '/usr/local/nagios/var/tmp';
@searches = (
{
    tag => 'dn42_datanode',
    logfile => '/home/hadoop/app/hadoop/logs/hadoop-hadoop-datanode-dn42pub.log',
    rotation => 'hadoop-hadoop-datanode-dn42pub.log.[0-9]',
    criticalpatterns => [
     'ERROR .*',
     'FAILURE .*',
    ]

},
{
    tag => 'dn42_nm',
    logfile => '/home/hadoop/app/hadoop/logs/yarn-hadoop-nodemanager-dn42pub.log',
    rotation => 'yarn-hadoop-nodemanager-dn42pub.log.[0-9]',
    criticalpatterns => [
     'ERROR .*',
     'FAILURE .*',
    ]

},
);

我这里没有配置warningpatterns,暂时没有此需要,如果有需要可以配置上。

c.在nrpe里面配置命令:

command[check_logfiles]=/usr/local/nagios/libexec/check_logfiles -f /usr/local/nagios/etc/log.cfg

d.在nagios服务器端配置这台机器的配置文件,在原有的配置文件中添加新的服务。(原来我放在nn1上/usr/local/nagios/etc/servers/dn42pub.cfg中,只需要添加如下即可)

;;monitor hadoop datanode and nodemanager process log content
define service{
use test-service
host_name dn42pub
service_description log_check
check_command check_nrpe!check_logfiles
is_volatile           1
max_check_attempts    1
}

 

注意,我这里使用的test-service是我在template.cfg中配置的,重写了它的检查周期为一分钟,这里需要注意。

dn42端执行:service xinetd reload即可

在nagios服务器端使用命令 nagios –v /usr/local/nagios/etc/nagios.cfg

检查如果没有错误,使用service nagios reload即可。

但是我在web端看到是unknown状态,这是因为nagios用户没有对日志目录的访问权限。

遂做以下修改。

chmod 705 /home/hadoop

即可。

3。其他机器如果需要安装,则可以如下操作,

直接scp /usr/local/nagios/libexec/check_logfiles targethost:/usr/local/nagios/libexec

makedir –p /usr/local/nagios/var/tmp

chown –R nagios:nagios /usr/local/nagios/var/tmp

修改nrpe.cfg 和并复制修改log.cfg即可

常见的问题,

我们通常会有这样的考虑,第一次运用nagios来检查文件的时候,文件可能很大了,而且会有很多旧的错误,会不会超时之类的,那check_logfiles是怎么处理的呢?

如果你不把type=>'virtual',则它是不会从头检查文件的,它只会检查文件的字节数,存一个offset,下次才会读新的数据。这正是我们想要的。这个问题我邮件咨询了

作者,以下是他的回复。

If you run check_logfiles for the first time, it does not scan the file. It positions at the end of the file and saves the position. (If it would start from the beginning, you would get very old errors)

When you run check_logfiles for the second time, it reads the saved position and then reads the _new lines_ which were appended in the meantime.

check_logfiles only scans new lines. (normally. if you use type=virtual, it scans the whole file all the time)

 

posted on 2015-12-19 07:22  tneduts  阅读(561)  评论(0编辑  收藏  举报

导航