溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Nagios、RRDTool和PNP整合

發(fā)布時(shí)間:2020-07-08 01:23:24 來源:網(wǎng)絡(luò) 閱讀:1528 作者:wiker 欄目:移動(dòng)開發(fā)

Nagios 性能分析圖標(biāo)的作用

    Nagios對(duì)服務(wù)或主機(jī)監(jiān)控的是一個(gè)瞬時(shí)狀態(tài),有時(shí)候系統(tǒng)管理員需要了解主機(jī)在一段時(shí)間內(nèi)的性能及服務(wù)的響應(yīng)狀態(tài),并且形成圖表,這就需要通過查看日志數(shù)據(jù)來分析。但是這種方式不僅煩瑣,而且抽象。為了能更直觀的查看主機(jī)運(yùn)行狀態(tài),這里采用PNP 來實(shí)現(xiàn)此功能。PNP 是一個(gè)小巧的開源軟件包,它是基于 PHP 和 Perl 腳本編寫,PNP 可以利用 rrdtool 工具將 Nagios采集的數(shù)據(jù)繪制成圖表,然后顯示主機(jī)或者服務(wù)在一段時(shí)間內(nèi)運(yùn)行的狀況。以下詳細(xì)介紹 PNP 安裝配置流程:


安裝 RRDtool 工具可以編譯安裝 RRDtool,也可以直接yum安裝


#yum install rrdtool -y


編譯安裝 PNP


下載站點(diǎn):http://docs.pnp4nagios.org/start版本分為 0.6.x0.4.x兩個(gè)版本

#tar zxvf pnp-0.4.13.tar.gz
#cd pnp-0.4.13
#./configure\
 --with-nagios-user=nagios \
 --with-nagios-group=nagios \
 --with-rrdtoul=/usr/local/rrdto
ol/bin/rrdtool \
--with-perfdata-dir=/usr/local/nagios/share/perfdata
編譯的時(shí)候會(huì)報(bào)

checking for PerlModule Time::HiRes... no

configure: error:Perl Module Time::HiRes not available

錯(cuò)誤,需要安裝#perl-Time-HiRes

#makeall
#make install
#make install-config
#make install-init

1. PNP配置文件定義

在 PNP安裝完成后, 默認(rèn)安裝目錄下回自帶相應(yīng)的模板配置文件, 因此只需要參考相應(yīng)的模板文件進(jìn)行修改即可,

PNP 配置文件定義


# cd/usr/local/nagios/etc/pnp/
# cp process_perfdata.cfg-sample process_perfdata.cfg
# cp npcd.cfg-sample npcd.cfg
# cp rra.cfg-sample rra.cfg
# chown -R nagios:nagios /usr/local/nagios/etc/pnp

2.修改process_perfdata.cfg 文件

打開 Nagios下的 process_perfdata.cfg 文件,修改相關(guān)內(nèi)容。可從下圖的注釋信息了解到

將數(shù)字 0 變更為2 是開啟了日志的調(diào)試功能,操作如下:

開啟日志調(diào)試功能

# vim/usr/local/nagios/etc/pnp/process_perfdata.cfg

LOG_FILE =/usr/local/nagios/var/perfdata.log

#

# Loglevel 0=silent1=normal 2=debug

#

LOG_LEVEL = 2


3.修改Nagios 相關(guān)配置文件

  • 增加流量圖圖標(biāo)

修改templates.cfg,增加一個(gè)定義 PNP 的 host 和 service,詳細(xì)見下圖 :

PNP 配置與設(shè)定

# vim /usr/local/nagios/etc/objects/templates.cfg #添加下面兩行

define host{

      name       hosts-pnp

      register   0

      action_url/nagios/pnp/index.php?host=$HOSTNAME$

      #process_perf_data  1

      }


define service{

      name        services-pnp

      register     0

      action_url  /nagios/pnp/index.php?host=$HOSTNAME$&srv=$SERVICEDESC$


  • 修改 nagios.cfg

如果想讓nagios 將數(shù)據(jù)輸出,首先要修改 nagios 的主配置文件 nagios.cfg,找到如下幾項(xiàng),如有注釋的將其去掉。修改后的信息如下:

增加 nagios 數(shù)據(jù)輸出設(shè)置


#vim/usr/local/nagios/etc/nagios.cfg
process_performance_data=1
host_perfdata_command=process-host-perfdata
service_perfdata_command=process-service-perfdata

  • 修改 commands.cfg

process-host-perfdata和 process-service-perfdata 指令聲明了 nagios 輸出哪些值到輸出文件中。 不過這些定義相對(duì)簡(jiǎn)單,而 PNP 提供了一個(gè)Perl 腳本,非常詳細(xì)地定義了一個(gè)輸出數(shù)據(jù)的方法,process_perfdata.pl 其實(shí)是 PNP 自帶的一個(gè)腳本,這個(gè)腳本在 PNP安裝完成后會(huì)自動(dòng)生成。因此,可以將 process-host-perfdata 和 process-service-perfdata指令中對(duì)應(yīng)的執(zhí)行命令的內(nèi)容替換成此腳本。增加下圖的內(nèi)容:

在 commands.cfg 文件中增加性能圖片配置

# vim /usr/local/nagios/etc/objects/commands.cfg #首先注釋掉下面的兩個(gè),然后添加下面這個(gè)

define command{

       command_name    process-host-perfdata

       command_line    $USER1$/process_perfdata.pl -d HOSTPERFDATA

       }


define command{

      command_name     process-service-perfdata

      command_line     $USER1$/process_perfdata.pl

       }


  • 修改 hosts.cfg 與 services.cfg

將hosts-pnp 和 services-pnp 引用到 hosts.cfg 和 services.cfg 中,修改后的 hosts.cfg 內(nèi)容如圖 13和圖 14 所示:

給三個(gè)主機(jī)的配置文件中增加性能圖片配置

# vim/usr/local/nagios/etc/objects/localhost.cfg
define host{
        use                    linux-server,hosts-pnp                                                                
        host_name               localhost
        alias                   localhost
        address                 127.0.0.1
        process_perf_data        1
        }
# vim/usr/local/nagios/etc/objects/windows.cfg
define host{
        use             windows-server,hosts-pnp      
        host_name       winserver     
        alias           My Windows Server     
        address         192.168.0.5    
        }
# vim/usr/local/nagios/etc/objects/linuxserver.cfg
define host{
        use             linux-server,hosts-pnp 
        host_name       linuxserver    
        alias           My linux Server
        address         192.168.0.3   
        }


主機(jī)配置文件內(nèi)給這三個(gè)主機(jī)的服務(wù)增加性能圖片配置


# vim /usr/local/nagios/etc/objects/linuxserver.cfg
define service{
        use                    generic-service,services-pnp
        host_name               linuxserver
        service_description     CHECK USERS
        check_command           check_nrpe!check_users
        }
define service{
        use                    generic-service,services-pnp
        host_name               linuxserver
        service_description     Load
        check_command           check_nrpe!check_load
        }
define service{
        use                    generic-service,services-pnp
        host_name               linuxserver
        service_description     SDA1
        check_command           check_nrpe!check_sda1
        }
define service{
        use                    generic-service,services-pnp
        host_name               linuxserver
        service_description     SDA2
        check_command           check_nrpe!check_sda2
        }
define service{
        use                    generic-service,services-pnp
        host_name               linuxserver
        service_description     Zombie
        check_command           check_nrpe!check_zombie_procs
        }
define service{
        use                    generic-service,services-pnp
        host_name               linuxserver
        service_description     Total_procs
        check_command           check_nrpe!check_total_procs
        }
define service{
        use                    generic-service,services-pnp
        host_name               linuxserver
        service_description     Swap
        check_command           check_nrpe!check_swap
        }
define service{
        use                    generic-service,services-pnp
        host_name               linuxserver
        service_description     Rootdisk
        check_command           check_nrpe!check_rootdisk
        }
# vim /usr/local/nagios/etc/objects/windows.cfg
define service{
        use                    generic-service,services-pnp
        host_name               winserver
        service_description     NSClient++ Version
        check_command           check_nt!CLIENTVERSION
        }
define service{
        use                    generic-service,services-pnp
        host_name               winserver
        service_description     Uptime
        check_command           check_nt!UPTIME
        }
define service{
        use                    generic-service,services-pnp
        host_name               winserver
        service_description     CPU Load
        check_command           check_nt!CPULOAD!-l 5,80,90
        }
define service{
        use                    generic-service,services-pnp
        host_name               winserver
        service_description     Memory Usage
        check_command           check_nt!MEMUSE!-w 80 -c 90
        }
        use                    generic-service,services-pnp
        host_name               winserver
        service_description     C:\ Drive Space
        check_command           check_nt!USEDDISKSPACE!-l c -w 80 -c90
        }
define service{
        use                    generic-service,services-pnp
        host_name               winserver
        service_description     W3SVC
        check_command           check_nt!SERVICESTATE!-d SHOWALL -lW3SVC
        }
define service{
        use                    generic-service,services-pnp
        host_name               winserver
        service_description     Explorer
        check_command           check_nt!PROCSTATE!-d SHOWALL -lExplorer.exe
        }
define service{
        use                    generic-service,services-pnp
        host_name               winserver
        service_description     Web_server
        check_command           check_http
        }
# vim /usr/local/nagios/etc/objects/localhost.cfg
define service{
        host_name                       localhost
        service_description             PING
        check_command                  check_ping!100.0,20%!500.0,60%
        }
define service{
        host_name                       localhost
        service_description             Root Partition
        check_command                   check_local_disk!20%!10%!/
        }
# if > 50 users.
        host_name                       localhost
        service_description             Current Users
        check_command                   check_local_users!20!50
        }
define service{
        host_name                       localhost
        service_description             Total Processes
        check_command                  check_local_procs!250!400!RSZDT
        }
# Define a service tocheck the load on the local machine.
        host_name                       localhost
        service_description             Current Load
        }
        host_name                       localhost
        service_description             Swap Usage
        check_command                   check_local_swap!20!10
        }
define service{
        use                            local-service,services-pnp        ; Name of service template to use
        host_name                       localhost
        service_description             SSH
        check_command                   check_ssh
        notifications_enabled           0
        }
define service{
        use                            local-service,services-pnp        ; Name of service template to use
        host_name                       localhost
        service_description             HTTP
        check_command                   check_http
        notifications_enabled           0
        }
#/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
…………………………...
Total Warnings: 0
Total Errors:   0
然后重啟服務(wù)
# service nagiosrestart
Running configurationcheck...done.
Stopping nagios:done.
Starting nagios:done.


然后登陸nagios管理界面,你就可看到主機(jī)和服務(wù)前面的性能圖標(biāo)

點(diǎn)擊圖標(biāo)的時(shí)候如果你沒有安裝php-gd的話,就會(huì)提示“php gd support not found”,直接yum安裝就可以

剛開始的時(shí)候,你點(diǎn)擊那個(gè)流量圖標(biāo),可能會(huì)提示錯(cuò)誤,如下,這只是rrd數(shù)據(jù)庫還沒有生成,所以沒有發(fā)現(xiàn),等一會(huì)就不會(huì)有這個(gè)提示了

Nagios、RRDTool和PNP整合

過一段時(shí)間以后,你點(diǎn)主機(jī)和服務(wù)的性能圖標(biāo)的話就會(huì)有流量圖顯示;

Nagios、RRDTool和PNP整合


Nagios、RRDTool和PNP整合


向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI