⑴安装完nagios,继续安装pnp,要注意rrdtool的安装。tar -xvzf pnp-0.4.13.tar.gz cd pnp-0.4.13 ./configuremake all make install make install-config make install-init---------------------------------------------------------------------------------FAQ:*** Configuration summary for pnp 0.4.13 02-19-2009 *** General Options: ------------------------- ------------------- Nagios user/group: nagios nagios Install directory: /usr/local/nagios HTML Dir: /usr/local/nagios/share/pnp Config Dir: /usr/local/nagios/etc/pnp Path to rrdtool: /usr/local/bin/rrdtool (Version 1.2.23) RRDs Perl Modules: *** NOT FOUND *** RRD Files stored in: /usr/local/nagios/share/perfdata process_perfdata.pl Logfile: /usr/local/nagios/var/perfdata.log Perfdata files (NPCD) stored in: /usr/local/nagios/var/spool/perfdata/-----------------------------------------process_perfdata.pl 安装在 /usr/local/nagios/share/配置示例文件安装在/usr/local/nagios/libexecsconfig.php安装于/usr/local/nagios/etc/pnp⑵修改配置文件①cd /usr/local/nagios/etc/pnp/cp process_perfdata.cfg-sample process_perfdata.cfg cp npcd.cfg-sample npcd.cfgcp rra.cfg-sample rra.cfg chown -R nagios:nagios *②vi /usr/local/nagios/etc/pnp/process_perfdata.cfg....LOG_FILE = /usr/local/nagios/var/perfdata.log # # Loglevel 0=silent 1=normal 2=debug # LOG_LEVEL = 2 #先改为2,为debug模式③
修改etc/objects/templates.cfg增加新命令(增加小太阳标记) #在use的后面添加"host-pnp"即可让监控图上的主机名称旁边增加一个小太阳的标记,点击此标记即可查看pnp图片。 define host { name host-pnp register 0 action_url /nagios/pnp/index.php?host=$HOSTNAME$ process_perf_data 1 } #还可以在service栏添加srv-pnp,添加后会在相应的栏内增加小太阳。 define service { name srv-pnp register 0 action_url /nagios/pnp/index.php?host=$HOSTNAME$&srv=$SERVICEDESC$ process_perf_data 1 }④修改etc/nagios.cfg找到如下几项,去掉注释 process_performance_data=1 host_perfdata_command=process-host-perfdata service_perfdata_command=process-service-perfdata⑤
修改commands.cfg # '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 }⑥nginx下的安全问题,需作如下配置修改pnp的web服务器配置文件nginx.conf,请注意安全问题,我这里未做安全验证。
location /pnp/ { root /usr/local/nagios/share/; location ~ .*/.php?$ { #fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fcgi.conf; } } 如果开启了open_basedir还需修改php.ini open_basedir = "/opt/htdoc:/opt/php/lib/php:/tmp/session:/tmp/upload:/usr/local/nagios/share/pnp:/usr/local/nagios/etc/pnp:/usr/local/nagios/share/perfdata:/usr/local/rrdtool/bin/rrdtool㈢测试:为localhost这台主机在主机图标旁边添加个小太阳标记vi /usr/local/nagios/etc/nagios.cfg#为这个主机增加小太阳标记define host{ use linux-server,host-pnp host_name localhost alias localhost address 127.0.0.1 }#重新加载配置文件service nagios reload 如果正确此时就会生成pnp文件[root@localhost ~]# ls /usr/local/nagios/share/perfdata/localhost/Current_Load.rrd Current_Users.xml PING.rrd Root_Partition.xmlCurrent_Load.xml HTTP.rrd PING.xml Swap_Usage.rrdCurrent_Users.rrd HTTP.xml Root_Partition.rrd Swap_Usage.xml打开网页http://localhost/nagios点击小太阳就可以看到图表,同访问http://localhost/nagios/pnpFAQ: 注意可能提示这个模块没有安装:Time/HiRes.pm模块的安装:①执行以下命令安装该模块。#perl -MCPAN -e 'install Time::HiRes' 或安装Time-HiRes-1.9707.tar.gz②如果打开pnp页面提示Hostname is not set,则检查etc/pnp/里的sample文件都更改正确,检查templates.cfg文件中url的正确性,还不行就等等,别太心急了,装完没那么快出图。