nagios 监控(四) pnp+rrdtools 图形分析

nagios 监控(四) pnp+rrdtools 图形分析
系统:Centos 5.2
1、准备工作
所需软件包
pnp                 下载地址:http://sourceforge.net
rrdtools
apache+php
perl
 
wget http: //oss.oetiker.ch/rrdtool/pub/rrdtool-1.3.7.tar.gz
安装php
yum install php-gd php
 
apache配置php
修改Apache的配置文件httpd.conf:
# vi /usr/local/apache/conf/httpd.conf
在AddType application/x-gzip .gz .tgz下,添加下面的配置项:
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

/etc/init.d/httpd restart    重启apache服务
 
PNP是一个小巧的开源软件包,它是基于PHP和PERL,利用rrdtool将Nagios采集的数据绘制成图表
 
安装rrdtools软件包
安装rrdtool之前确保安装了这些库 zlib libpng freetype libart_lgpl cairo-devel pango-devel
mkdir /usr/local/rrdtool
tar zxvf rrdtools
./configure --prefix=/usr/local/rrdtool
make && make install
 
注:rrdtools无法生成图形,apache 错误日志提示:
[Fri Sep 04 21:03:05 2009] [error] [client 222.182.1.170] Can't locate RRDs.pm in @INC (@INC contains: /usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.7/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.6/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl/5.8.7 /usr/lib/perl5/site_perl/5.8.6 /usr/lib/perl5/site_perl/5.8.5 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.7/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.6/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.5/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl/5.8.7 /usr/lib/perl5/vendor_perl/5.8.6 /usr/lib/perl5/vendor_perl/5.8.5 /usr/lib/perl5/vendor_perl /usr/lib/perl5/5.8.8/i386-linux-thread-multi /usr/lib/perl5/5.8.8 .) at /usr/local/nagios/sbin/show.cgi line 9., referer: http://61.123.11.2/nagios/cgi-bin/status.cgi?host=all
[Fri Sep 04 21:03:05 2009] [error] [client 222.182.1.170] BEGIN failed--compilation aborted at /usr/local/nagios/sbin/show.cgi line 9., referer: http: // 61.123.11.2/nagios/cgi-bin/status.cgi?host=all
解决方法:
 
cp -rp /usr/local/rrdtool/lib/perl/5.8.8/i386-linux-thread-multi/* /usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi

出现
Can't locate LWP/UserAgent.pm in @INC (@INC contains: /usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl /usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/5.8.8 .) at hot_mover10.pl line 7.
BEGIN failed--compilation aborted at hot_mover10.pl line 7.


解决办法
[root@pnp]# perl -MCPAN -eshell    
cpan> install Bundle::LWP


安装pnp软件包
tar zxvf pnp
./configure --with-rrdtool=/usr/local/rrdtool/bin/rrdtool --with-perfdata-dir=/usr/local/nagios/share/perfdata/    
make all    
make install
2、配置nagios配置文件
修改主配置文件nagios.cfg
在定义host或service中都有一个定义项,名为process_perf_data,其值可以定义为0或1,其作用是是否启用Nagios的数据输出功能。如果你将此项赋值为1,那么Nagios就会将收集的数据写入到某个文件中,以备提取
vi /usr/local/nagios/etc/nagios.cfg
process_performance_data= 1
service_perfdata_command=process-service-perfdata    #将些句前面的注释去掉
对某个监控对象做数据图表,则需在所对应的host或者service定义中
process_perf_data 1
define host{
                use                            generic-host                     
                host_name                  web-1.72
                alias                           web-server
                address                       192.168.1.72
                check_command            check-host-alive
                max_check_attempts     10
                check_period                24x7
                notification_interval       20
                notification_period         24x7
                notification_options        d,r
                contact_groups             admins
                 process_perf_data         1 
                }
Nagios就会调用相应的命令来输出数据了。Nagios的command定义中默认有一项“process-service-perfdata”,该命令声明了Nagios输出哪些值到输出的文件中。不过其定义相对简单,PNP提供了一个perl脚本,更详尽的定义了一个输出数据的方法。如果要使用PNP的话,我们需要在command的定义中,将“process-service-perfdata”命令对应的执行命令行的内容替换成该脚本:
define command{    
        command_name process-service-perfdata 
        command_line /usr/local/nagios/libexec/process_perfdata.pl    
}
process_perfdata.pl文件是安装了pnp软件包,自动在/usr/local/nagios/libexec目录下生成的。
3、检查nagios配置是否正确
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
重新载加nagios配置,并重启服务!
/etc/init.d/nagios reload
/etc/init.d/nagios restart
4、测试
在IE里输入 http://locallost/nagios/pnp 如下图所示!

你可能感兴趣的:(职场,nagios,pnp,休闲,rrdtools)