nagios+rrdtoll+pnp个人参考资料

nagios+rrdtool+pnp 分析图表

(2012-04-18 16:13:42)
转载
 

    nagios 对服务或主机监控的是一个瞬时状态,有时候管理员需要了解主机一段时间内的性能及服务的响应状态,并且形成图表,这时就会用到pnp。

    pnp是基于php和perl的,pnp可以利用rrdtool工具将nagios采集的数据绘制成相关的图表,然后显示主机或者服务在一段时间内的运行状况。

    如果要安装pnp,需要安装如下环境:

    1)整合后的apache和php环境,需支持GD、zlib、jpeg

    2)安装rrdtool工具

    3)安装perl

1.安装PNP

    首先安装rrdtool-1.4.5.tar.gz

    ./configure --prefix=/usr/local/rrdtool

    make

    make install

   

    接着安装pnp-0.4.13.tar.gz

    ./configure --with-nagios-user=nagios  --with-nagios-group-nagios --with-rrdtool==/usr/local/rrdtool/bin/rrdtool --with-perfdata-dir=/usr/local/nagios/share/perfdata

    make all

    make install

    make install-config

    make install-init

2.配置PNP

    (1)创建默认配置文件

    cd /usr/local/nagios/etc/pnp

    cp npcd.cfg-sample npcd.cfg

    cp process_perfdata.cfg-sample process_perfdata.cfg

    cp rra.cfg-sample rra.cfg

    chown -R nagios.nagios /usr/local/nagios/etc/pnp

   (2)修改process_perfdata.cfg文件

     LOG_FILE = /usr/local/nagios/var/perfdata.log
     #
     # Loglevel 0=silent 1=normal 2=debug
     #
     LOG_LEVEL = 2

     这里将日志级别改为2,即debug模式

3.修改nagios配置文件

     (1)修改nagios.cfg

       pnp是通过调用nagios的数据来生成图表的,所以需要开启nagios的数据输出功能

       process_performance_data=1    ###开启数据输出功能

       host_perfdata_command=process-host-perfdata
       service_perfdata_command=process-service-perfdata

     (2)修改commands.cfg

      process-host-perfdata和process-service-perfdata指令声明了nagios输出哪些值到输出文件,pnp定义了一个perl脚本process_perfdata.pl,可以将指令中对应的执行命令替换成此脚本

      # 'process-host-perfdata' command definition

      define command{
       command_name    process-host-perfdata
       command_line    /usr/local/nagios/libexec/process_perfdata.pl
        }

      # 'process-service-perfdata' command definition

      define command{
        command_name    process-service-perfdata
        command_line    /usr/local/nagios/libexec/process_perfdata.pl
        }
     (3)修改hosts.cfg和services.cfg文件

       在hosts.cfg文件中增加以下代码:

       define host {
        name    hosts-pnp
        register        0
        action_url      /nagios/pnp/index.php?host=$HOSTNAME$
        process_perf_data       1
       }

       并给每个主机增加一句:

       use   hosts-pnp  意思是将hosts-pnp引用

       在services.cfg文件中增加以下代码:

       define service {
        name    services-pnp
        register        0
        action_url      /nagios/pnp/index.php?host=$HOSTNAME$&srv=$SERVICEDESC$
        process_perf_data       1
       }

       并给每个服务增加一句:

       use   services-pnp  意思是将services-pnp引用

4.测试pnp功能

       重启nagios

       /etc/init.d/nagios  restart

       在目录/usr/local/nagios/share/perfdata下会生成以主机名命名的文件夹

       访问主页,在每个主机后面会有一个小太阳图标,点击进行就能看见图表了

5.报错修改

     (1)点击小太阳也能会报以下这种错误:

       Warning: date() [function.date]: It is not safe to rely on the system's timezone settings.You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Asia/Chongqing' for 'CST/8.0/no DST' instead in /usr/local/nagios/share/pnp/include/function.inc.php on line 557

Deprecated: Function eregi() is deprecated in /usr/local/nagios/share/pnp/include/function.inc.php on line 1541

Deprecated: Function eregi() is deprecated in /usr/local/nagios/share/pnp/include/function.inc.php on line 1541

Deprecated: Function eregi() is deprecated in /usr/local/nagios/share/pnp/include/function.inc.php on line 1541

        这是因为pnp-0.4.14对PHP 5.3.0的支持还不是很好,其中有几个bug需要修改:

        根据错误提示打开

        vi /usr/local/nagios/share/pnp/include/function.inc.php

        找到行1541附近修改为

        if($level == 2 && $type == "complete" && preg_match("/^NAGIOS_/",$tag)){

        还会有两处错误需要修改,根据提示找到对应行进行修改:

        line 556: 添加:date_default_timezone_set('UTC');
        line 1033:修改为$pdf = new PDF('P', 'mm', 'A4'); 删除&

 

        再重新重启nagios,应该就能看到图表了

 

            (2) 安装rrdtool时会报错
                  configure: error: Please fix the library issues listed above and try again.
                  需要安装rpm包:
                    cairo-1.2.4-5.el5.i386.rpm
                    cairo-devel-1.2.4-5.el5.i386.rpm
                    pango-1.14.9-6.el5.centos.i386.rpm             
                    pango-devel-1.14.9-6.el5.centos.i386.rpm

 

 

终于搞定搞定,中间安装的时候还报了很多次错误,大部分都是你的包没有装完全,只要按照错误提示把相应的包安装好就OK了,先确认是否有以下rpm包:

   rpm -qa |grep zlib  

        zlib-1.1.4-8

        zlib-devel-1.1.4-8

   rpm -qa |grep libpng 
       libpng-1.2.10-7.1.el5_3.2
       libpng-devel-1.2.10-7.1.el5_3.2  

   rpm -qa |grep freetype
       freetype-2.2.1-21.el5_3
       freetype-devel-2.2.1-21.el5_3

   rpm -qa |grep  libart_lgpl

        libart_lgpl-devel-2.3.17-4
        libart_lgpl-2.3.17-4

 

 

-----------

pnp4nagios “RRDs Perl Modules: *** NOT FOUND ***”  

2012-03-16 13:38:34|  分类: 默认分类 |  标签: |字号 订阅

 

已安装rrdtool
1.检查模块是否存在:
[root@localhost pnp4nagios-0.6.16]# perl -MRRDs -le 'print q(ok!)'
Can't locate RRDs.pm in @INC (@INC contains: /usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl /usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/5.8.8 .).
BEGIN failed--compilation aborted.
 

[root@localhost pnp4nagios-0.6.16]#ln -s /usr/local/rrdtool-1.4.7/lib/perl/5.8.8/x86_64-linux-thread-multi/RRDs.pm /usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/

2.此检查模块是否存在:
[root@localhost pnp4nagios-0.6.16]# perl -MRRDs -le 'print q(ok!)'
Can't locate loadable object for module RRDs in @INC (@INC contains: /usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl /usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/5.8.8 .) at -e line 0
Compilation failed in require.
BEGIN failed--compilation aborted.

[root@localhost pnp4nagios-0.6.16]# ln -s /usr/local/rrdtool-1.4.7/lib/perl/5.8.8/x86_64-linux-thread-multi/auto/RRDs/RRDs.so /usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/

3.此次检查模块是否存在:
[root@localhost pnp4nagios-0.6.16]# perl -MRRDs -le 'print q(ok!)'
ok!

 

----

要实现Nagios数据的图像化需要使用第三方的软件,PNPNagios可以完成这个任务,PNPNagios的原名为php,下载地址为http://sourceforge.net/projects/pnp4nagios/,它利用RRDTool工具将Nagios的数据生成图形,以便更直观的查看,而且可以查看历史记录。

 

PNPNagios的安装与设置

 

如果解决了PNPNagios软件的依赖性,那么它还是比较好安装的,因此在具体的安装中,首先要根据下面提到的“软件依赖性”安装相关的软件或者模块,然后再安装PNPNagios软件。

软件依赖性

 

    要安装使用pnp4nagios需要以下软件:

 

u       Perl >= 5.x,不需要其它额外的模块;

u       RRDtool >= 1.x1.2版本更好,但是并不强制使用这个版本;

u       PHP >= 5.1.6 基于Kohanaweb前端的需要;

u       Nagios >= 2.x 或者是Icinga

u       Kohana需要启用“mod_rewrite”模块

 

    注意:安装RRDtool没有安装包管理器可能会导致丢失dejavu字体,如果查看图像没有字体时,那么可能是由于这个问题引起的。

 

下载安装

 

首先来安装rrdtool,在这里比较简单的节选了部分安装过程:

 

 

[root@ff ~]# tar -zxvf rrdtool- 1.2.15 .tar.gz

[root@ff ~]# cd rrdtool- 1.2.15

[root@ff rrdtool- 1.2.15 ]# ./configure

 

 

----------------------------------------------------------------

Config is DONE!

 

          With MMAP IO: yes

          Perl Modules: perl_piped perl_shared

           Perl Binary: /usr/bin/perl

          Perl Version: 5.8.5

          Perl Options: PREFIX=/usr/local/rrdtool- 1.2.15 LIB=/usr/local/rrdtool-1.2.15/lib/perl/5.8.5

    Build Tcl Bindings: yes

 Build Python Bindings: yes

          Build rrdcgi: yes

       Build librrd MT: yes

 

 

Type 'make' to compile the software and use 'make install' to

install everything to: /usr/local/rrdtool- 1.2.15 .

 

       ... that wishlist is NO JOKE. If you find RRDtool useful

make me happy. Go to http://people.ee.ethz.ch/oetiker/wish and

place an order.

 

                               -- Tobi Oetiker <[email protected]>

----------------------------------------------------------------

[root@ff rrdtool- 1.2.15 ]# make

[root@ff rrdtool- 1.2.15 ]# make install

 

因为下面的安装中需要rrdtool的安装目录,因此在这里有必要提一下,下面来下载并安装PNP4Nagios

 

 

点击上面的图标下载最新版本的安装包,下面是命令行的下载:

 

[root@s10 ~]# wget http://jaist.dl.sourceforge.net/project/pnp4nagios/PNP-0.6/pnp4nagios- 0.6.17 .tar.gz

--16:03:19--  http://jaist.dl.sourceforge.net/project/pnp4nagios/PNP-0.6/pnp4nagios- 0.6.17 .tar.gz

           => `pnp4nagios- 0.6.17 .tar.gz'

正在解析主机 jaist.dl.sourceforge.net... 150.65.7.130

正在连接 jaist.dl.sourceforge.net[150.65.7.130]:80... 已连接。

已发出 HTTP 请求,正在等待回应... 200 OK

长度:3,006,338 [application/x-gzip]

 

100%[===========================>] 3,006,338    709.85K/s    ETA 00:00

 

16:03:25 (649.88 KB/s) - `pnp4nagios- 0.6.17 .tar.gz' saved [3,006,338/3,006,338]

 

[root@s10 ~]#

 

解压安装包:

 

[root@ff ~]# tar -zxvf pnp4nagios- 0.6.17 .tar.gz

[root@ff ~]# cd pnp4nagios- 0.6.17

 

    执行configure

 

[root@ff pnp4nagios- 0.6.17 ]#  ./configure --prefix=/usr/local/pnp4nagios --with-rrdtool=/usr/local/rrdtool-1.2.15/bin/rrdtool

 

*** Configuration summary for pnp4nagios-0.6.17 03-25-2012 ***

 

  General Options:

  -------------------------         -------------------

  Nagios user/group:                nagios nagios

  Install directory:                /usr/local/pnp4nagios

  HTML Dir:                         /usr/local/pnp4nagios/share

  Config Dir:                       /usr/local/pnp4nagios/etc

  Location of rrdtool binary:    /usr/local/rrdtool- 1.2.15 /bin/rrdtool Version 1.2.15

  RRDs Perl Modules:                *** NOT FOUND ***

  RRD Files stored in:              /usr/local/pnp4nagios/var/perfdata

  process_perfdata.pl Logfile:      /usr/local/pnp4nagios/var/perfdata.log

  Perfdata files (NPCD) stored in:  /usr/local/pnp4nagios/var/spool

 

  Web Interface Options:

  -------------------------         -------------------

  HTML URL:                         http://localhost/pnp4nagios

  Apache Config File:               /etc/httpd/conf.d/pnp4nagios.conf

 

 

  Review the options above for accuracy.  If they look okay,

  type 'make all' to compile.

 

 

  WARNING: The RRDs Perl Modules are not found on your system

           Using RRDs will speedup things in larger installations.

   

注意提示,这个错误的原因是没有找到RRD perl模块,查看RRDTool的安装包,确实是在下面的路径中存在:

 

[root@ff ~]# ll /usr/local/rrdtool- 1.2.15 /lib/perl/5.8.5/i386-linux-thread-multi/

total 16

-r--r--r--  1 root root 3850 Jul 14  2006 RRDs.pm

drwxr-xr-x  4 root root 4096 Jun  8 16:34 auto

-r--r--r--  1 root root 1215 Jul 14  2006 ntmake.pl

-rw-r--r--  1 root root  456 Jun  8 16:34 perllocal.pod

[root@ff ~]#

   

    解决方法使用--with-perl_lib_path选项:

   

[root@ff pnp4nagios- 0.6.17 ]#  ./configure --prefix=/usr/local/pnp4nagios  \

> --with-rrdtool=/usr/local/rrdtool- 1.2.15 /bin/rrdtool  \

> --with-perl_lib_path=/usr/local/rrdtool- 1.2.15 /lib/perl/   \

> 5.8.5 /i386-linux-thread-multi/

 

*** Configuration summary for pnp4nagios-0.6.17 03-25-2012 ***

 

  General Options:

  -------------------------       -------------------

  Nagios user/group:              nagios nagios

  Install directory:              /usr/local/pnp4nagios

  HTML Dir:                       /usr/local/pnp4nagios/share

  Config Dir:                     /usr/local/pnp4nagios/etc

  Location of rrdtool binary:     /usr/local/rrdtool- 1.2.15 /bin/rrdtool Version 1.2.15

  RRDs Perl Modules:              FOUND (Version 1.2015)

  RRDs Perl search path:

                /usr/local/rrdtool- 1.2.15 /lib/perl/5.8.5/i386-linux-thread-multi/

  RRD Files stored in:              /usr/local/pnp4nagios/var/perfdata

  process_perfdata.pl Logfile:      /usr/local/pnp4nagios/var/perfdata.log

  Perfdata files (NPCD) stored in:  /usr/local/pnp4nagios/var/spool

 

  Web Interface Options:

  -------------------------         -------------------

  HTML URL:                         http://localhost/pnp4nagios

  Apache Config File:               /etc/httpd/conf.d/pnp4nagios.conf

 

 

  Review the options above for accuracy.  If they look okay,

  type 'make all' to compile.

 

   

你可能感兴趣的:(nagios,pnp,naigos)