您好,登錄后才能下訂單哦!
Nagios 性能分析圖標的作用
Nagios對服務或主機監控的是一個瞬時狀態,有時候系統管理員需要了解主機在一段時間內的性能及服務的響應狀態,并且形成圖表,這就需要通過查看日志數據來分析。但是這種方式不僅煩瑣,而且抽象。為了能更直觀的查看主機運行狀態,這里采用PNP 來實現此功能。PNP 是一個小巧的開源軟件包,它是基于 PHP 和 Perl 腳本編寫,PNP 可以利用 rrdtool 工具將 Nagios采集的數據繪制成圖表,然后顯示主機或者服務在一段時間內運行的狀況。以下詳細介紹 PNP 安裝配置流程:
安裝 RRDtool 工具可以編譯安裝 RRDtool,也可以直接yum安裝
#yum install rrdtool -y
編譯安裝 PNP
下載站點:http://docs.pnp4nagios.org/start版本分為 0.6.x和0.4.x兩個版本
#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
編譯的時候會報
checking for PerlModule Time::HiRes... no
configure: error:Perl Module Time::HiRes not available
錯誤,需要安裝#perl-Time-HiRes
#makeall
#make install
#make install-config
#make install-init
1. PNP配置文件定義
在 PNP安裝完成后, 默認安裝目錄下回自帶相應的模板配置文件, 因此只需要參考相應的模板文件進行修改即可,
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 文件,修改相關內容。可從下圖的注釋信息了解到
將數字 0 變更為2 是開啟了日志的調試功能,操作如下:
開啟日志調試功能
# 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 相關配置文件
增加流量圖圖標
修改templates.cfg,增加一個定義 PNP 的 host 和 service,詳細見下圖 :
PNP 配置與設定
# 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 將數據輸出,首先要修改 nagios 的主配置文件 nagios.cfg,找到如下幾項,如有注釋的將其去掉。修改后的信息如下:
增加 nagios 數據輸出設置
#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 輸出哪些值到輸出文件中。 不過這些定義相對簡單,而 PNP 提供了一個Perl 腳本,非常詳細地定義了一個輸出數據的方法,process_perfdata.pl 其實是 PNP 自帶的一個腳本,這個腳本在 PNP安裝完成后會自動生成。因此,可以將 process-host-perfdata 和 process-service-perfdata指令中對應的執行命令的內容替換成此腳本。增加下圖的內容:
在 commands.cfg 文件中增加性能圖片配置
# vim /usr/local/nagios/etc/objects/commands.cfg #首先注釋掉下面的兩個,然后添加下面這個
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 內容如圖 13和圖 14 所示:
在給三個主機的配置文件中增加性能圖片配置
# 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 }
在主機配置文件內給這三個主機的服務增加性能圖片配置
# 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 然后重啟服務 # service nagiosrestart Running configurationcheck...done. Stopping nagios:done. Starting nagios:done.
然后登陸nagios管理界面,你就可看到主機和服務前面的性能圖標
點擊圖標的時候如果你沒有安裝php-gd的話,就會提示“php gd support not found”,直接yum安裝就可以
剛開始的時候,你點擊那個流量圖標,可能會提示錯誤,如下,這只是rrd數據庫還沒有生成,所以沒有發現,等一會就不會有這個提示了
過一段時間以后,你點主機和服務的性能圖標的話就會有流量圖顯示;
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。