nagios 对服务或主机监控的是一个瞬时状态,有时候管理员需要了解主机一段时间内的性能及服务的响应状态,并且形成图表,这时就会用到pnp。
pnp是基于php和perl的,pnp可以利用rrdtool工具将nagios采集的数据绘制成相关的图表,然后显示主机或者服务在一段时间内的运行状况。
如果要安装pnp,需要安装如下环境:
1)整合后的apache和php环境,需支持GD、zlib、jpeg
2)安装rrdtool工具
3)安装perl
1.安装PNP
首先安装rrdtool-1.4.5.tar.gz
./configure --prefix=/usr/local/rrdtool
make
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