pnp4nagios是nagios的一個插件,用於將perfdata數據寫入rrd,用於展現流量圖,目前最高版本0.6.25。php
我用官方下載的tar.gz打rpm包,官方提供的pnp4nagios.spec 須要更改幾處,才能順利打包python
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支持多種rrd生成模式,我選擇Bulk Mode with NPCD和Gearman Mode模式ios
nagios.cfgbash
# 開啓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\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tHOSTPERFDATA::$HOSTPERFDATA$\tHOSTCHECKCOMMAND::$HOSTCHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$ service_perfdata_file_template=DATATYPE::SERVICEPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tSERVICEDESC::$SERVICEDESC$\tSERVICEPERFDATA::$SERVICEPERFDATA$\tSERVICECHECKCOMMAND::$SERVICECHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$\tSERVICESTATE::$SERVICESTATE$\tSERVICESTATETYPE::$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.phpui
$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.cfg3d
# 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.phpunix
默認模板裏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