nagios + pnp图形化

 

nagios功能很多,最主要是有报警功能,但是nagios也有一个缺点,就是自身没有图形化工具,要另外去装pnp4nagios,网上大部分都是结合apache的,下面说一下pnp4nagios配合nginx的配置

一,安装pnp4nagios

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

如果找不到包换epel源,博客里面有搜一下。关于nagios的安装,请参考:nagios 安装配置 详解

二,配置nagios

1,修改nagios.cfg

查看复制打印?

  1. [root@localhost objects]# vim /etc/nagios/nagios.cfg    //修改以下内容  

  2. process_performance_data=1                             //由0改为1  

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

4、修改配置文件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 管理页面

转载于:https://my.oschina.net/u/2618722/blog/663331

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值