1. 程式人生 > >Nagios插件Nagiosgraph安裝部署

Nagios插件Nagiosgraph安裝部署

nagios perl cpan nagiosgraph

Nagios是比較常用的一款開源監控軟件,Nagios靈活輕便使得在使用時可以根據自己的實際情況靈活運用,但是Nagios有一個缺點是對繪圖做的不夠完善,所以在對監控數據用來做分析時Nagios就有短板了。不過因為Nagios的靈活所以Nagios可以借助其他的方式實現圖形報表的展示,今天在此就簡要的說一說官方的Nagiosgraph插件,Nagiosgraph插件是用過Perl來實現的,所以在使用用Nagiosgraph插件時就要確保系統中安裝了Perl以及配置好相應的cpan源,這樣才能進行安裝,至於cpan的源配置以前有提及過,這裏就不做說明,需要可以參看:http://jim123.blog.51cto.com/4763600/1895093 。Nagiosgraph插件的官方下載地址:https://sourceforge.net/projects/nagiosgraph/files/ ,建議下載最新穩定版,安裝部署前需要先檢查系統中是否有安裝插件所需的依賴包:

[[email protected] nagiosgraph-1.5.2]# perl install.pl --check-prereq#像這樣就是所有的插件都有安裝了
checking required PERL modules
  Carp...1.11
  CGI...3.51
  Data::Dumper...2.124
  Digest::MD5...2.39
  File::Basename...2.77
  File::Find...1.14
  MIME::Base64...3.08
  POSIX...1.17
  RRDs...1.3008
  Time::HiRes...1.9721
checking optional PERL modules
  GD...2.44
  Nagios::Config...36
checking nagios installation
  found nagios exectuable at /usr/local/nagios/bin/nagios
  found nagios init script at /etc/init.d/nagios
checking web server installation
  found apache executable at /usr/sbin/httpd
  found apache init script at /etc/init.d/httpd

如果找到那一沒有安裝就安裝下,建議在配置好yum源或者是apt源後進行安裝如GD繪圖安裝:

[[email protected] nagiosgraph-1.5.2]# yum -y install perl-GD

這裏一般都會缺少安裝Perl下的Nagios::Config模塊,在配置好cpan源後使用cpan安裝

[[email protected] nagiosgraph-1.5.2]# cpan Nagios::Config#註意有的時候還會缺少Digest::MD5模塊等同理依次安裝即可

在解決所有的依賴關系後就可以開始安裝配置,在安裝時會有提示默認選項直接按回車就進行下一步

[[email protected] nagiosgraph-1.5.2]# perl install.pl

在安裝好後需要註意,最後會有提示需要在Nagios中做一些配置更改配置及操作方法,如:

# process nagios performance data using nagiosgraph
process_performance_data=1
service_perfdata_file=/tmp/perfdata.log
service_perfdata_file_template=$LASTSERVICECHECK$||$HOSTNAME$||$SERVICEDESC$||$SERVICEOUTPUT$||$SERVICEPERFDATA$
service_perfdata_file_mode=a
service_perfdata_file_processing_interval=30
service_perfdata_file_processing_command=process-service-perfdata-for-nagiosgraph
#修改Nagios的配置文件,在nagios.cfg添加

/bin/systemctl restart  httpd.service



  * In the nagios commands file (command.cfg),
    add these lines:

# command to process nagios performance data for nagiosgraph
define command {
  command_name process-service-perfdata-for-nagiosgraph
  command_line /usr/local/nagiosgraph/bin/insert.pl
}
#添加修改command.cfg配置文件

  * In the apache configuration file (httpd.conf),
    add this line:

Include /usr/local/nagiosgraph/etc/nagiosgraph-apache.conf
#在Nagios的用的httpd配置文件中添加nagiosgraph的包含
  * Check the nagios configuration:

/usr/local/nagios/bin/nagios -v /path/to/nagios.cfg

  * Restart nagios to start data collection:

/etc/init.d/nagios restart

  * Restart apache to enable display of graphs:

/etc/init.d/httpd restart
#最後在多項檢查重啟後完成配置
  * To enable graph links and mouseovers, see README sections:
       Displaying Per-Service and Per-Host Graph Icons and Links
       Displaying Graphs in Nagios Mouseovers

同Nagios一樣打開頁面配置檢查頁面:http://IP/nagiosgraph/cgi-bin/showconfig.cgi技術分享

確認沒有問題後再到Nagios的share文件夾下修改Nagios的php頁面文件side.php添加Nagiosgraph的鏈接制作偽靜態頁:

<?php $nagiosgraph_path = ‘/nagiosgraph/cgi-bin‘;?>
<li><a >Nagios圖表</a></li>

<ul>

<li><a href="<?php echo $nagiosgraph_path;?>/show.cgi" target="<?php echo $link_target;?>">圖表</a></li>
<li><a href="<?php echo $nagiosgraph_path;?>/showhost.cgi" target="<?php echo $link_target;?>">主機圖表</a></li>
<li><a href="<?php echo $nagiosgraph_path;?>/showservice.cgi" target="<?php echo $link_target;?>">服務圖表</a></li>
<li><a href="<?php echo $nagiosgraph_path;?>/showgroup.cgi" target="<?php echo $link_target;?>">主機組圖表</a></li>

</ul>
</li>

最後在Nagios的頁面下就有Nagiosgraph的圖表鏈接技術分享

技術分享

根據要選定的主機和服務生成圖表,總之Nagiosgraph的配置是依賴於Perl配置起來還是比較簡單的,但是生成的圖表並不是非常的完美,不過也能滿足日常的一些簡單的分析,但是如果需要更好可以借助替他軟件或插件實現,Nagios的圖表展示。

本文出自 “技術隨筆” 博客,謝絕轉載!

Nagios插件Nagiosgraph安裝部署