nagios + pnp圖形化

 

nagios功能不少,最主要是有報警功能,可是nagios也有一個缺點,就是自身沒有圖形化工具,要另外去裝pnp4nagios,網上大部分都是結合apache的,下面說一下pnp4nagios配合nginx的配置php

一,安裝pnp4nagioscss

  1. [root@localhost objects]# yum install pnp4nagios rrdtool  html

若是找不到包換epel源,博客裏面有搜一下。關於nagios的安裝,請參考:nagios 安裝配置 詳解linux

二,配置nagiosios

1,修改nagios.cfgnginx

查看複製打印?web

  1. [root@localhost objects]# vim /etc/nagios/nagios.cfg    //修改如下內容  apache

  2. process_performance_data=1                             //由0改成1  vim

  3. host_perfdata_command=process-host-perfdata            //前面的註釋拿掉  服務器

  4. service_perfdata_command=process-service-perfdata      //註釋拿掉  

  5. enable_environment_macros=1                            //若是有註釋拿掉  

2,修改commands.cfg

註釋掉原有對process-host-perfdata和process-service-perfdata,從新定義

  1. [root@localhost objects]# vim /etc/nagios/objects/commands.cfg  

  2.   

  3. define command {  

  4.        command_name    process-service-perfdata  

  5.        command_line    /usr/bin/perl /usr/libexec/pnp4nagios/process_perfdata.pl  #根據實際路徑

  6. }  

  7.   

  8. define command {  

  9.        command_name    process-host-perfdata  

  10.        command_line    /usr/bin/perl /usr/libexec/pnp4nagios/process_perfdata.pl #根據實際路徑

  11. }  

四、修改配置文件templates.cfg

添加如下內容

查看複製打印?

  1. [root@localhost objects]# vim /etc/nagios/objects/templates.cfg   

  2.   

  3. define host {  

  4.         name       hosts-pnp  

  5.         register   0  

  6.         action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=_HOST_  

  7.         process_perf_data               1  

  8. }  

  9. define service {  

  10.         name       srv-pnp  

  11.         register   0  

  12.         action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$  

  13.         process_perf_data               1  

  14. }  

5,修改服務器配置文件localhost.cfg

查看複製打印?

  1. [root@localhost objects]# vim /etc/nagios/objects/localhost.cfg  

  2.   

  3. define host{  

  4.         use                     linux-server,hosts-pnp  

  5.         host_name               localhost  

  6.         alias                   localhost  

  7.         address                 127.0.0.1  

  8.         }  

  9.   

  10. define service{  

  11.         use                             local-service,srv-pnp  

  12.         host_name                       localhost  

  13.         service_description             PING  

  14.         check_command                   check_ping!100.0,20%!500.0,60%  

  15.         }  

上面只是例舉了一個,你能夠都加一下。

三,pnp4nagios配置

在網上好多關於pnp4nagios的文章,都是要把mv misccommands.cfg-sample misccommands.cfg 生成配置文件,我是yum安裝的,安裝目錄下根本沒有sample這樣的東西

  1. [root@localhost objects]# tree /etc/pnp4nagios/  

  2. /etc/pnp4nagios/  

  3. ├── background.pdf  

  4. ├── check_commands  

  5. │   ├── check_all_local_disks.cfg  

  6. │   ├── check_nrpe.cfg  

  7. │   └── check_nwstat.cfg  

  8. ├── config.php  

  9. ├── misccommands.cfg  

  10. ├── nagios.cfg  

  11. ├── npcd.cfg  

  12. ├── pages  

  13. │   └── web_traffic.cfg  

  14. ├── pnp4nagios_release  

  15. ├── process_perfdata.cfg  

  16. └── rra.cfg  

所在我根本沒有配置任何東西。

四,重啓nagios,啓動npcd

  1. [root@localhost pnp4nagios]# /etc/init.d/npcd start  

  2. [root@localhost pnp4nagios]# /etc/init.d/nagios restart  

五,nginx配置

配置nginx的時候,配置挺頭痛的,nagios的根目錄是有php的,pnp4nagios是放在nagios的根目錄下面,pnp4nagios也是php的,配置很差容易錯亂的。

查看複製打印?

  1. server  

  2. {  

  3.     listen       80;  

  4.     server_name  nagios.xxxx.com;  

  5.     index  index.php;  

  6.     root   /usr/share/nagios/html;  

  7.   

  8.     location ~ .*\.(php|php5)?$ {        //nagios根目錄的php  

  9.         fastcgi_pass  127.0.0.1:9000;  

  10.         fastcgi_index index.php;  

  11.         include fastcgi.conf;  

  12.     }  

  13.   

  14.     location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {   //nagios的圖片重寫  

  15.         rewrite ^/nagios/images/(.*) /images/$1 break;  

  16.         rewrite ^/pnp4nagios/index.php/(.*) /pnp4nagios/$1 break;  

  17.         expires     30d;  

  18.     }  

  19.   

  20.     location ~ .*\.(js|css)?$ {       //nagios的js,css重寫  

  21.         rewrite ^/nagios/stylesheets/(.*) /stylesheets/$1 break;  

  22.         rewrite ^/nagios/js/(.*) /js/$1 break;  

  23.         rewrite ^/pnp4nagios/index.php/(.*) /pnp4nagios/$1 break;  

  24.         expires     1h;  

  25.     }  

  26.   

  27.     location ~ .*\.cgi$ {             //nagios的主程序是perl的,perl的cgi重寫  

  28.         root /usr/lib64/nagios/cgi-bin;  

  29.         rewrite ^/nagios/cgi-bin/(.*)\.cgi /$1.cgi break;  

  30.         fastcgi_pass   127.0.0.1:9001;  

  31.         fastcgi_index index.cgi;  

  32.         include fastcgi.conf;  

  33.     }  

  34.     location ~ ^(/pnp4nagios.*\.php)(.*)$ {       //pnp4nagios的php重寫  

  35.         rewrite ^/pnp4nagios/index.php/index.php/(.*)$ /pnp4nagios/index.php/$1break;  

  36.         fastcgi_pass   127.0.0.1:9000;  

  37.         fastcgi_index index.php;  

  38.         include fastcgi.conf;  

  39.     }  

  40.   

  41. }  

在這裏有一個問題就是http://nagios.xxxx.com/pnp4nagios/index.php/index.php/graph?host=localhost&srv=PING在這裏有二個index.php,這個是php的程序加上去的,我並無改。同一個頁面有二種連接。

由nagios的監控頁面,跳轉到pnp4nagios監控頁面的鏈接是

http://nagios.xxxx.com/pnp4nagios/index.php/graph?host=localhost&srv=PING

點php4nagios監控頁面中的鏈接而後就會多加一個index.php,

http://nagios.xxxx.com/pnp4nagios/index.php/index.php/graph?host=localhost&srv=PING

這也是上面我爲何要加這一句rewrite ^/pnp4nagios/index.php/index.php/(.*)$ /pnp4nagios/index.php/$1; break;的緣由

看一下效果圖

nagios 監控頁面看到pnp4nagios圖標,折線小圖

nagios 監控頁面看到pnp4nagios圖標,折線小圖

點擊上圖中的折線小圖,進入下圖

pnp4nagios 管理頁面

pnp4nagios 管理頁面

相關文章
相關標籤/搜索