pnp4nagios是nagios的一个插件,用于将perfdata数据写入rrd,用于展示流量图,目前最高版本0.6.25。
我用官方下载的tar.gz打rpm包,官方提供的pnp4nagios.spec 需要更改几处,才能顺利打包
version: 0.6.16 =>0.6.25
%build
--with-perfdata-spool-dir=%{_localstatedir}/spool/nagios => --with-perfdata-spool-dir=%{_localstatedir}/nagios/spool
%files
增加
%{_libexecdir}/rrd_modify.pl
pnp4nagios 依赖 php-gd 还有rrdtool-perl,这个记得一定不能少。
pnp4nagios支持多种rrd生成模式,我选择Bulk Mode with NPCD和Gearman Mode模式
nagios.cfg
# 开启perfdata数据生成
process_performance_data=1
# perfdata数据位置
host_perfdata_file=/var/nagios/host-perfdata
service_perfdata_file=/var/nagios/service-perfdata
# perfdata数据模板
host_perfdata_file_template=DATATYPE::HOSTPERFDATA TIMET::$TIMET$ HOSTNAME::$HOSTNAME$ HOSTPERFDATA::$HOSTPERFDATA$ HOSTCHECKCOMMAND::$HOSTCHECKCOMMAND$ HOSTSTATE::$HOSTSTATE$ HOSTSTATETYPE::$HOSTSTATETYPE$
service_perfdata_file_template=DATATYPE::SERVICEPERFDATA TIMET::$TIMET$ HOSTNAME::$HOSTNAME$ SERVICEDESC::$SERVICEDESC$ SERVICEPERFDATA::$SERVICEPERFDATA$ SERVICECHECKCOMMAND::$SERVICECHECKCOMMAND$ HOSTSTATE::$HOSTSTATE$ HOSTSTATETYPE::$HOSTSTATETYPE$ SERVICESTATE::$SERVICESTATE$ SERVICESTATETYPE::$SERVICESTATETYPE$
host_perfdata_file_mode=a
service_perfdata_file_mode=a
host_perfdata_file_processing_interval=15
service_perfdata_file_processing_interval=15
# perfdata数据文件处理命令,这个与pnp4nagios相关
host_perfdata_file_processing_command=process-host-perfdata-file
service_perfdata_file_processing_command=process-service-perfdata-file
commands
# 与Bulk Mode with NPCD模式对应,对应图示 - 步骤3
define command {
command_name process-host-perfdata-file
command_line /bin/mv /var/nagios/host-perfdata /var/nagios/spool/host-perfdata.$TIMET$
}
define command {
command_name process-service-perfdata-file
command_line /bin/mv /var/nagios/service-perfdata /var/nagios/spool/service-perfdata.$TIMET$
}
config.php
$views[] = array('title' => 'One Hour', 'start' => (60*60) );
$conf['RRD_DAEMON_OPTS'] = 'unix:/var/run/rrdcached.sock';
npcd.cfg
# 日志,用于调试
log_type = file
log_file = /var/log/nagios/npcd.log
log_level = 1
# pnp4nagios spool目录,与commands.cfg要对应
perfdata_spool_dir = /var/nagios/spool
npcd_max_threads = 10
# /var/nagios/spool目录扫描间隔
sleep_time = 15
process_perfdata.cfg
# rrd存储目录,与pnp4nagios的config.php对应
RRDPATH = /usr/share/pnp4nagios/perfdata
# 日志,用于调试
LOG_FILE = /var/log/nagios/perfdata.log
LOG_LEVEL = 1
# 使用rrdcached降低压力
RRD_DAEMON_OPTS = unix:/var/run/rrdcached.sock
/usr/share/pnp4nagios/templates.dist/default.php
默认模板里rrdtool配置参数与rrdtool 1.6不兼容,需要修改
--lower => --lower-limit
--upper => --upper-limit
启动
systemctl restart nagios
systemctl restart npcd
mod-gearman
#/etc/mod_gearman/module.conf
perfdata=yes
perfdata_send_all=yes
perfdata_mode=1
process_perfdata.cfg
# rrd存储目录,与pnp4nagios的config.php对应
RRDPATH = /usr/share/pnp4nagios/perfdata
# 日志,用于调试
LOG_FILE = /var/log/nagios/perfdata.log
LOG_LEVEL = 1
# 使用rrdcached降低压力
RRD_DAEMON_OPTS = unix:/var/run/rrdcached.sock
# 子进程数量
PREFORK = 20
# 指定gearmand服务器的地址
GEARMAN_HOST = xxx.xxx.xxx.xxx:4730
启动
systemctl restart nagios
systemctl restart pnp_gearmand_work