Previous Article Next Article nagios 使用 pnp4nagios 畫 rrdtool 圖,像 MRTG 圖表
Posted in Linux

nagios 使用 pnp4nagios 畫 rrdtool 圖,像 MRTG 圖表

nagios 使用 pnp4nagios 畫 rrdtool 圖,像 MRTG 圖表 Posted on 2013 年 12 月 19 日Leave a comment

安裝 php4nagios

wget pnp4nagios-0.6.21
./configure --prefix=/usr/local/pnp4nagios --with-nagios-user=nagios --with-nagios-group=nagios
make all
make fullinstall

編輯 vi /usr/local/nagios/etc/nagios.cfg

process_performance_data=1
host_perfdata_command=process-host-perfdata
service_perfdata_command=process-service-perfdata

編輯 /usr/local/nagios/etc/commands.d/commands.cfg

define command{
 command_name process-host-perfdata
 command_line /usr/bin/perl /usr/local/pnp4nagios/libexec/process_perfdata.pl -d HOSTPERFDATA
}
define command{
 command_name process-service-perfdata
 command_line /usr/bin/perl /usr/local/pnp4nagios/libexec/process_perfdata.pl
}

編輯 /usr/local/nagios/etc/templates.d/global-host.cfg 加入

(假如有在每個監控的主機設定裡使用 use global-host 的話就在對的地方加,否則設定於每個 cfg 裡,這可以讓 nagios web 介面可以點選圖形連結 )

php4nagios

action_url /pnp4nagios/graph?host=$HOSTNAME$&srv=_HOST_

編輯 /usr/local/nagios/etc/templates.d/global-service.cfg 加入

action_url /pnp4nagios/graph?host=$HOSTNAME$&srv=$SERVICEDESC$

驗證 pnp4nagios 對不對

/root/pnp4nagios-0.6.21/scripts/verify_pnp_config_v2.pl -m sync -c /usr/local/nagios/etc/nagios.cfg -p /usr/local/pnp4nagios/etc | egrep -v '\[(OK|INFO)'

pnp4nagios 建議用 bulk+npcd
[HINT] Use at least mode ‘bulk+npcd’ to reduce I/O

編輯 /usr/local/nagios/etc/nagios.cfg

process_performance_data=1
service_perfdata_file=/usr/local/pnp4nagios/var/service-perfdata
service_perfdata_file_template=DATATYPE::SERVICEPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tSERVICEDESC::$SERVICEDESC$\tSERVICEPERFDATA::$SERVICEPERFDATA$\tSERVICECHECKCOMMAND::$SERVICECHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$\tSERVICESTATE::$SERVICESTATE$\tSERVICESTATETYPE::$SERVICESTATETYPE$
service_perfdata_file_mode=a
service_perfdata_file_processing_interval=15
service_perfdata_file_processing_command=process-service-perfdata-file
host_perfdata_file=/usr/local/pnp4nagios/var/host-perfdata
host_perfdata_file_template=DATATYPE::HOSTPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tHOSTPERFDATA::$HOSTPERFDATA$\tHOSTCHECKCOMMAND::$HOSTCHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$
host_perfdata_file_mode=a
host_perfdata_file_processing_interval=15
host_perfdata_file_processing_command=process-host-perfdata-file

編輯 /usr/local/nagios/etc/commands.d/commands.cfg

## Bulk with NPCD mode
define command {
 command_name process-service-perfdata-file
 command_line /bin/mv /usr/local/pnp4nagios/var/service-perfdata /usr/local/pnp4nagios/var/spool/service-perfdata.$TIMET$
}
define command {
 command_name process-host-perfdata-file
 command_line /bin/mv /usr/local/pnp4nagios/var/host-perfdata /usr/local/pnp4nagios/var/spool/host-perfdata.$TIMET$
}

驗證

/root/pnp4nagios-0.6.21/scripts/verify_pnp_config_v2.pl -m bulk+npcd -c /usr/local/nagios/etc/nagios.cfg -p /usr/local/pnp4nagios/etc | egrep -v '\[(OK|INFO)'

讓圖表可以縮圖 (滑鼠移過去時,但我試不成功)

mkdir /usr/local/pnp4nagios/share/ssi
cp -rp contrib/ssi/status-header.ssi /usr/local/pnp4nagios/share/ssi

並設定 url,改成如下

action_url /pnp4nagios/graph?host=$HOSTNAME$&srv=_HOST_' class='tips' rel='/pnp4nagios/popup?host=$HOSTNAME$&srv=_HOST_
與
action_url /pnp4nagios/graph?host=$HOSTNAME$&srv=$SERVICEDESC$' class='tips' rel='/pnp4nagios/popup?host=$HOSTNAME$&srv=$SERVICEDESC$

裝完把 /usr/local/pnp4nagios/share/install.php 刪除或移掉

啟動服務

/etc/init.d/npcd start
/etc/init.d/httpd graceful
/etc/init.d/nagios reload

Q : 如果遇到 magic_quotes_gpc 相關問題,就把它 Off

A : 編輯 /etc/httpd/conf.d/pnp4nagios.conf 加入

php_admin_flag magic_quotes_gpc Off

Q &A : 如果 PHP 有 disable_function 的話,php4nagios 是需要 proc_open 的

Q:

Please check the documentation for information about the following error.
XML file “/usr/local/pnp4nagios/var/perfdata/010101.com.tw/http.xml” not parsable.
XML Errors:
Input is not proper UTF-8, indicate encoding ! Bytes: 0xB5 0xEA 0xC0 0xC0
file [line]:
application/models/data.php [276]:

A: 沒答案

Q&A : rrdttool在處理大量的rrd文件時,會造成系統相對較高的I/O負載,利用rrdcaced,可以緩解對大量rrd文件多次隨機寫入的問題,它會緩存這些寫入,批量進行更新,來減少disk I/O。注意檢查RRDtool版本是否支持該特性。

Q&A : http://www.verydemo.com/demo_c128_i52914.html 也有一種設定,不過我還沒試

#定義監控的服務
define serviceextinfo {
host_name mylinux #與主機名對應
service_description remote_load #與要顯示的服務對應
action_url /pnp4nagios/index.php/graph? host =$HOSTNAME$& srv =$SERVICEDESC$’ class = ‘tips’ rel =’/pnp4nagios/index.php/popup? host =$HOSTNAME$& srv =$SERVICEDESC$
}
#這是向nagios 監控界面對應服務添加pnp4nagios圖標的方法
說明:pnp4naigos在安裝關聯nagios後會對所監控的服務進行圖形化顯示,但是並非所有服務都會自動在nagios監視見面出現pnp4nagios的圖標,故用以上字段予以定義。

 

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *