Nagios、RRDTool和PNP整合
让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:域名注册、虚拟空间、营销软件、网站建设、文山州网站维护、网站推广。
Nagios 性能分析图标的作用
Nagios对服务或主机监控的是一个瞬时状态,有时候系统管理员需要了解主机在一段时间内的性能及服务的响应状态,并且形成图表,这就需要通过查看日志数据来分析。但是这种方式不仅烦琐,而且抽象。为了能更直观的查看主机运行状态,这里采用PNP 来实现此功能。PNP 是一个小巧的开源软件包,它是基于 PHP 和 Perl 脚本编写,PNP 可以利用 rrdtool 工具将 Nagios采集的数据绘制成图表,然后显示主机或者服务在一段时间内运行的状况。以下详细介绍 PNP 安装配置流程:
安装 RRDtool 工具可以编译安装 RRDtool,也可以直接yum安装
#yum install rrdtool -y
编译安装 PNP
下载站点:http://docs.pnp4nagios.org/start版本分为 0.6.x和0.4.x两个版本
#tar zxvf pnp-0.4.13.tar.gz
#cd pnp-0.4.13
#./configure\
--with-nagios-user=nagios \
--with-nagios-group=nagios \
--with-rrdtoul=/usr/local/rrdtool/bin/rrdtool \
--with-perfdata-dir=/usr/local/nagios/share/perfdata
编译的时候会报
checking for PerlModule Time::HiRes... no
configure: error:Perl Module Time::HiRes not available
错误,需要安装#perl-Time-HiRes
#makeall
#make install
#make install-config
#make install-init
1. PNP配置文件定义
在 PNP安装完成后, 默认安装目录下回自带相应的模板配置文件, 因此只需要参考相应的模板文件进行修改即可,
PNP 配置文件定义
# cd/usr/local/nagios/etc/pnp/
# cp process_perfdata.cfg-sample process_perfdata.cfg
# cp npcd.cfg-sample npcd.cfg
# cp rra.cfg-sample rra.cfg
# chown -R nagios:nagios /usr/local/nagios/etc/pnp
2.修改process_perfdata.cfg 文件
打开 Nagios下的 process_perfdata.cfg 文件,修改相关内容。可从下图的注释信息了解到
将数字 0 变更为2 是开启了日志的调试功能,操作如下:
开启日志调试功能
# vim/usr/local/nagios/etc/pnp/process_perfdata.cfg
LOG_FILE =/usr/local/nagios/var/perfdata.log
#
# Loglevel 0=silent1=normal 2=debug
#
LOG_LEVEL = 2
3.修改Nagios 相关配置文件
增加流量图图标
修改templates.cfg,增加一个定义 PNP 的 host 和 service,详细见下图 :
PNP 配置与设定
# vim /usr/local/nagios/etc/objects/templates.cfg #添加下面两行
define host{
name hosts-pnp
register 0
action_url/nagios/pnp/index.php?host=$HOSTNAME$
#process_perf_data 1
}
define service{
name services-pnp
register 0
action_url /nagios/pnp/index.php?host=$HOSTNAME$&srv=$SERVICEDESC$
修改 nagios.cfg
如果想让nagios 将数据输出,首先要修改 nagios 的主配置文件 nagios.cfg,找到如下几项,如有注释的将其去掉。修改后的信息如下:
增加 nagios 数据输出设置
#vim/usr/local/nagios/etc/nagios.cfg
process_performance_data=1
host_perfdata_command=process-host-perfdata
service_perfdata_command=process-service-perfdata
修改 commands.cfg
process-host-perfdata和 process-service-perfdata 指令声明了 nagios 输出哪些值到输出文件中。 不过这些定义相对简单,而 PNP 提供了一个Perl 脚本,非常详细地定义了一个输出数据的方法,process_perfdata.pl 其实是 PNP 自带的一个脚本,这个脚本在 PNP安装完成后会自动生成。因此,可以将 process-host-perfdata 和 process-service-perfdata指令中对应的执行命令的内容替换成此脚本。增加下图的内容:
在 commands.cfg 文件中增加性能图片配置
# vim /usr/local/nagios/etc/objects/commands.cfg #首先注释掉下面的两个,然后添加下面这个
define command{
command_name process-host-perfdata
command_line $USER1$/process_perfdata.pl -d HOSTPERFDATA
}
define command{
command_name process-service-perfdata
command_line $USER1$/process_perfdata.pl
}
修改 hosts.cfg 与 services.cfg
将hosts-pnp 和 services-pnp 引用到 hosts.cfg 和 services.cfg 中,修改后的 hosts.cfg 内容如图 13和图 14 所示:
在给三个主机的配置文件中增加性能图片配置
# vim/usr/local/nagios/etc/objects/localhost.cfg define host{ use linux-server,hosts-pnp host_name localhost alias localhost address 127.0.0.1 process_perf_data 1 } # vim/usr/local/nagios/etc/objects/windows.cfg define host{ use windows-server,hosts-pnp host_name winserver alias My Windows Server address 192.168.0.5 } # vim/usr/local/nagios/etc/objects/linuxserver.cfg define host{ use linux-server,hosts-pnp host_name linuxserver alias My linux Server address 192.168.0.3 }
在主机配置文件内给这三个主机的服务增加性能图片配置
# vim /usr/local/nagios/etc/objects/linuxserver.cfg define service{ use generic-service,services-pnp host_name linuxserver service_description CHECK USERS check_command check_nrpe!check_users } define service{ use generic-service,services-pnp host_name linuxserver service_description Load check_command check_nrpe!check_load } define service{ use generic-service,services-pnp host_name linuxserver service_description SDA1 check_command check_nrpe!check_sda1 } define service{ use generic-service,services-pnp host_name linuxserver service_description SDA2 check_command check_nrpe!check_sda2 } define service{ use generic-service,services-pnp host_name linuxserver service_description Zombie check_command check_nrpe!check_zombie_procs } define service{ use generic-service,services-pnp host_name linuxserver service_description Total_procs check_command check_nrpe!check_total_procs } define service{ use generic-service,services-pnp host_name linuxserver service_description Swap check_command check_nrpe!check_swap } define service{ use generic-service,services-pnp host_name linuxserver service_description Rootdisk check_command check_nrpe!check_rootdisk } # vim /usr/local/nagios/etc/objects/windows.cfg define service{ use generic-service,services-pnp host_name winserver service_description NSClient++ Version check_command check_nt!CLIENTVERSION } define service{ use generic-service,services-pnp host_name winserver service_description Uptime check_command check_nt!UPTIME } define service{ use generic-service,services-pnp host_name winserver service_description CPU Load check_command check_nt!CPULOAD!-l 5,80,90 } define service{ use generic-service,services-pnp host_name winserver service_description Memory Usage check_command check_nt!MEMUSE!-w 80 -c 90 } use generic-service,services-pnp host_name winserver service_description C:\ Drive Space check_command check_nt!USEDDISKSPACE!-l c -w 80 -c90 } define service{ use generic-service,services-pnp host_name winserver service_description W3SVC check_command check_nt!SERVICESTATE!-d SHOWALL -lW3SVC } define service{ use generic-service,services-pnp host_name winserver service_description Explorer check_command check_nt!PROCSTATE!-d SHOWALL -lExplorer.exe } define service{ use generic-service,services-pnp host_name winserver service_description Web_server check_command check_http } # vim /usr/local/nagios/etc/objects/localhost.cfg define service{ host_name localhost service_description PING check_command check_ping!100.0,20%!500.0,60% } define service{ host_name localhost service_description Root Partition check_command check_local_disk!20%!10%!/ } # if > 50 users. host_name localhost service_description Current Users check_command check_local_users!20!50 } define service{ host_name localhost service_description Total Processes check_command check_local_procs!250!400!RSZDT } # Define a service tocheck the load on the local machine. host_name localhost service_description Current Load } host_name localhost service_description Swap Usage check_command check_local_swap!20!10 } define service{ use local-service,services-pnp ; Name of service template to use host_name localhost service_description SSH check_command check_ssh notifications_enabled 0 } define service{ use local-service,services-pnp ; Name of service template to use host_name localhost service_description HTTP check_command check_http notifications_enabled 0 } #/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg …………………………... Total Warnings: 0 Total Errors: 0 然后重启服务 # service nagiosrestart Running configurationcheck...done. Stopping nagios:done. Starting nagios:done.
然后登陆nagios管理界面,你就可看到主机和服务前面的性能图标
点击图标的时候如果你没有安装php-gd的话,就会提示“php gd support not found”,直接yum安装就可以
刚开始的时候,你点击那个流量图标,可能会提示错误,如下,这只是rrd数据库还没有生成,所以没有发现,等一会就不会有这个提示了
过一段时间以后,你点主机和服务的性能图标的话就会有流量图显示;
网页名称:Nagios、RRDTool和PNP整合
地址分享:http://myzitong.com/article/ggjdie.html