mycmasa 2012-11-07
实现nagios的图表显示
1、检查需要支持的系统套件是否都已经安装:
[root@localhost ]# yum install httpd php
[root@localhost ]# yum install gcc glibc glibc-common
[root@localhost ]# yum install gd gd-devel php-gd
2、安装需要支持的系统套件:
[root@localhost ]# rpm -ivh rpmforge-release-0.5.2-2.el5.rf.i386.rpm
(下载地址:http://packages.sw.be/rpmforge-release/ 选择相应版本下载)
[root@localhost ]# yum install rrdtool (安装绘图所需要的套件包)
3、安装nagios图表插件:(下载地址:http://sourceforge.net/projects/pnp4nagios/files/)
[root@localhost ]# tar -zxvf pnp4nagios-0.6.12.tar.gz
[root@localhost ]# cd pnp4nagios-0.6.12
[root@localhost ]# ./configure (默认安装路径是/usr/local/pnp4nagios)
[root@localhost ]# make all
[root@localhost ]# make install
[root@localhost ]# make fullinstall
[root@localhost ]# ls /usr/local/nagios/ (查看有无pnp4nagios目录,安装成功会有这个)
4、修改nagios程序中的配置:
(1)修改主配置程序nagios.cfg文件:
[root@localhost ]# vim /usr/local/nagios/etc/nagios.cfg
process_performance_data=0 (把这边的0改为1)
#host_perfdata_command=process-host-perfdata (去掉前面的注释号#)
#service_perfdata_command=process-service-perfdata (去掉前面的注释号#)
(2)修改命令配置程序commands.cfg文件:
[root@localhost ]# vim /usr/local/nagios/etc/objects/commands.cfg
# 'process-host-perfdata' command definition
define command{
command_name process-host-perfdata (主机定义的命令)
command_line /usr/local/pnp4nagios/libexec/process_perfdata.pl (修改这一行)
} (把原来的长串输出打印命令改为上面这个绘图控件执行)
# 'process-service-perfdata' command definition
define command{
command_name process-service-perfdata (服务定义的命令)
command_line /usr/local/pnp4nagios/libexec/process_perfdata.pl (修改这一行)
} (把原来的长串输出打印命令改为上面这个绘图控件执行)
(3)修改模板配置程序templates.cfg文件:
[root@localhost ]# vim /usr/local/nagios/etc/objects/templates.cfg
define service{
name generic-service
active_checks_enabled 1
passive_checks_enabled 1
parallelize_check 1
obsess_over_service 1
check_freshness 0
notifications_enabled 1
event_handler_enabled 1
flap_detection_enabled 1
failure_prediction_enabled 1
process_perf_data 1
retain_status_information 1
retain_nonstatus_information 1
is_volatile 0
check_period 24x7
max_check_attempts 3
normal_check_interval 10
retry_check_interval 2
contact_groups admins
notification_options w,u,c,r
notification_interval 60
notification_period 24x7
register 0
action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$
process_perf_data 1 (在最后面增加上下这两行)
}
(3)验证参数据修改是否正确并重新加载
[root@localhost ]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
[root@localhost ]# service nagios reload
[root@localhost ]# service httpd reload
5、查看并验证图表插件是否配置成功:
(1)登录nagios系统,如果在服务我旁边有一个小太阳的图表,并点击它,能够出来图表,说明配置已经成功了。
如果点击小太阳出来的是php的测试成功页面,如下图
PNP4Nagios Environment Tests
……
Your environment passed all requirements. Remove or rename
the /usr/local/pnp4nagios/share/install.php file now.
则按提示删除 /usr/local/pnp4nagios/share/目录下面的 indtall.pnp文件即可。
(2)删除成功以后,重新加载nagios和httpd服务并进入页面查看,就可以正常显示了图表了(注:加载图表需要一段时间,刚重启完查看可能会出错,因为图表还没画出来,需要等待一会儿)。
(3)pnp4nagios不能绘制图形的服务项目
对于windows平台下面的Uptime 与NSClient++ Version 及 Explorer 默认是不显示绘制图标的,会提示下面错误:
XML file "/usr/local/pnp4nagios/var/perfdata/winserver/Uptime.xml" not found
6、如何修改图表显示的小太阳图标:
如果觉得“小太阳”的图标比较难看,想改为“网络流量”的图标,只要把自己设计的图标命名为“action.gif”,并覆盖到 /usr/local/nagios/share/images/action.gif文件即可。