八、實現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
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文件即可。