nagios+rrdtoll+pnp我的參考資料

nagios+rrdtool+pnp 分析圖表

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

    nagios 對服務或主機監控的是一個瞬時狀態,有時候管理員須要瞭解主機一段時間內的性能及服務的響應狀態,而且造成圖表,這時就會用到pnp。javascript

    pnp是基於php和perl的,pnp能夠利用rrdtool工具將nagios採集的數據繪製成相關的圖表,而後顯示主機或者服務在一段時間內的運行情況。php

    若是要安裝pnp,須要安裝以下環境:html

    1)整合後的apache和php環境,需支持GD、zlib、jpeg前端

    2)安裝rrdtool工具java

    3)安裝perllinux

1.安裝PNPios

    首先安裝rrdtool-1.4.5.tar.gzweb

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

    makecentos

    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 <tobi@oetiker.ch>

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

[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.

相關文章
相關標籤/搜索