自由的风's Archivers

From 自由的风 on 2013-04-28 15:55:43

Nagios可视化绘制工具PNP安装&配置

Nagios是一款开源的免费网络监视工具,能有效监控Windows、Linux和Unix的主机状态,交换机路由器等网络设备以及打印机等。

PNP是一个基于php和perl,用rrdtool将nagios采集的数据绘制图表的工具。


Nagios安装和配置: http://loosky.net/archives/2758.html



Nagios监控配置:http://loosky.net/archives/2764.html



一、PNP安装



PNP下载地址:http://docs.pnp4nagios.org/pnp-0.6/install



因为PNP是一个基于php和perl,用rrdtool将nagios采集的数据绘制图表的工具,所以安装pnp之前必须先安装php、perl和rrdtool。这里用yum直接来安装rrdtool,单独下载安装有很多依存关系,比较麻烦。



#yum install rrdtool
#cd /usr/local/src
#wget http://sourceforge.net/projects/pnp4nagios/files/PNP-0.6/pnp4nagios-0.6.15.tar.gz/download //下载pnp
#tar xzvf pnp4nagios-0.6.15.tar.gz
#cd pnp4nagios-0.6.15
#./configure




此时有可能出现perl modules没有发现的错误:



<img src="http://loosky.net/Upload/2013/04/pnp-perl.png" alt="perl modules没有发现" />



解决方案:



#yum install rrdtool-perl


参考:http://ronaldbradford.com/blog/installing-perl-rrd-module-rrdspm-2009-07-11/



根据提示需要继续



# make all
# make fullinstall


安装成功后相关的文件信息如下:



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/bin/rrdtool Version 1.3.8
RRDs Perl Modules: FOUND (Version 1.3008)
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

PHP-Files for the web-frontend: /usr/local/pnp4nagios/share/pnp
data collector process_perfdata.pl:/usr/local/pnp4nagios/libexec
sample config files with the suffix -sample:/usr/local/pnpnagios/etc
config file config.php for the web frontend in:/usr/local/pnp4nagios/etc


然后把相关后缀带sample文件变更成无sample后缀 #cd /usr/local/pnp4nagios/etc #mv misccommands.cfg-sample misccommands.cfg #mv nagios.cfg-sample nagios.cfg #mv rra.cfg-sample rra.cfg



#cd pages
#mv web_traffic.cfg-sample web_traffic.cfg

#cd ../check_commands/
#mv check_all_local_disks.cfg-sample check_all_local_disks.cfg
#mv check_nrpe.cfg-sample check_nrpe.cfg
#mv check_nwstat.cfg-sample check_nwstat.cfg


二、配置Nagios来启用PNP



Nagios的配置文件中,enable_environment_macros=1默认是开启了的


pnp4nagios有很多种工作模式,参见:http://docs.pnp4nagios.org/pnp-0.6/config。这里我们选用同步模式,想选其它模式可以看说明都有详细配置教程。



定义命令

#vi /usr/local/nagios/etc/objects/commands.cfg //新增或修改如下内容

define command {
command_name process-service-perfdata
command_line /usr/bin/perl /usr/local/pnp4nagios/libexec/process_perfdata.pl
}

define command {
command_name process-host-perfdata
command_line /usr/bin/perl /usr/local/pnp4nagios/libexec/process_perfdata.pl -d HOSTPERFDATA
}


修改主机和服务模板

修改主机和服务模板,添加小太阳模版,镶嵌在nagios页面上(http://docs.pnp4nagios.org/pnp-0.6/webfe)



这里有两种查看图的方法,第一种方法是你当太阳的图标的时候会在新窗口中打开图形查看,第二种方法是你只需要把鼠标移动到太阳图标上面就会自动弹出图形出来,以下两种方法你可以根据自己喜好选其中一种即可



第一种方法在templates.cfg里面加入如下



define host {
name host-pnp
action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=_HOST_
register 0
}

define service {
name srv-pnp
action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$
register 0
}


第二种方法按照说明加入如下



拷贝status-header.ssi到/usr/local/nagios/share/ssi/目录下面来(这一步很重要,要不然移动到太阳标记上出不来图)



define host {
name host-pnp
action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=_HOST_' class='tips' rel='/pnp4nagios/index.php/popup?host=$HOSTNAME$&srv=_HOST_
register 0
}

define service {
name srv-pnp
action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$' class='tips' rel='/pnp4nagios/index.php/popup?host=$HOSTNAME$&srv=$SERVICEDESC$
register 0
}


为目标主机图标旁边添加一个小太阳标记:



<img src="http://loosky.net/Upload/2013/04/pnp-host.jpg" alt="" />



为相关服务添加一个小太阳标记



<img src="http://loosky.net/Upload/2013/04/pnp-service.jpg" alt="" />


查看完整版本: Nagios可视化绘制工具PNP安装&配置

Tags: Nagios, PNP, 监控


©自由的风