Nagios 性能分析圖標(biāo)的作用
創(chuàng)新互聯(lián)公司專注于淇縣企業(yè)網(wǎng)站建設(shè),響應(yīng)式網(wǎng)站設(shè)計(jì),商城網(wǎng)站制作。淇縣網(wǎng)站建設(shè)公司,為淇縣等地區(qū)提供建站服務(wù)。全流程按需制作網(wǎng)站,專業(yè)設(shè)計(jì),全程項(xiàng)目跟蹤,創(chuàng)新互聯(lián)公司專業(yè)和態(tài)度為您提供的服務(wù)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.x和0.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/rrdtool/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)容??蓮南聢D的注釋信息了解到
將數(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ì)簡單,而 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è)提示了
過一段時(shí)間以后,你點(diǎn)主機(jī)和服務(wù)的性能圖標(biāo)的話就會(huì)有流量圖顯示;
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。