nagios-新增oracle資料庫監控

君落塵發表於2014-11-05
[root@mi6 ~]# cd /usr/local/nagios/
[root@mi6 nagios]# ls
bin  etc  libexec  share
[root@mi6 nagios]# cd libexec/
[root@mi6 libexec]# ./check_oracle --help
check_oracle v1.5 (nagios-plugins 1.5)
The nagios plugins come with ABSOLUTELY NO WARRANTY. You may redistribute
copies of the plugins under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING.


Usage:
  check_oracle --tns
  check_oracle --db
  check_oracle --login
  check_oracle --connect
  check_oracle --cache
  check_oracle --tablespace
  check_oracle --oranames
  check_oracle --help
  check_oracle --version


Check Oracle status


--tns SID/IP Address
   Check remote TNS server
--db SID
   Check local database (search /bin/ps for PMON process) and check
   filesystem for sgadefORACLE_SID.dbf
--login SID
   Attempt a dummy login and alert if not ORA-01017: invalid username/password
--connect SID
   Attempt a login and alert if an ORA- error is returned
--cache
   Check local database for library and buffer cache hit ratios
       ---&gt  Requires Oracle user/password and SID specified.
                ---&gt  Requires select on v_ and v_
--tablespace
   Check local database for tablespace capacity in ORACLE_SID
       ---&gt  Requires Oracle user/password specified.
                ---&gt  Requires select on dba_data_files and dba_free_space
--oranames Hostname
   Check remote Oracle Names server
--help
   Print this help screen
--version
   Print version and license information


If the plugin doesn't work, check that the ORACLE_HOME environment
variable is set, that ORACLE_HOME/bin is in your PATH, and the
tnsnames.ora file is locatable and is properly configured.


When checking local database status your ORACLE_SID is case sensitive.


If you want to use a default Oracle home, add in your oratab file:
*:/opt/app/oracle/product/7.3.4:N


Send email to nagios-users@lists.sourceforge.net if you have questions
regarding use of this software. To submit patches or suggest improvements,
send email to nagiosplug-devel@lists.sourceforge.net.
Please include version information with all correspondence (when possible,
use output from the --version option of the plugin itself).
[root@mi6 libexec]# 












配置修改如下:
被監控端(oracle資料庫伺服器)
[root@mi6 libexec]# cd /usr/local/nagios/libexec
1、新增oracle的環境變數
[root@mi6 libexec]# vi check_oracle 
export ORACLE_SID=mi1
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
export PATH=$ORACLE_HOME/bin:/bin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/X11R6/bin
2、檢測命令是否生效
[root@mi6 libexec]# ./check_oracle --tns mi           ###mi是tns名字
OK - reply time 0 msec from mi
[root@mi6 libexec]# ./check_oracle --db mi1           ###mi1是例項名
mi1 OK - 1 PMON process(es) running
[root@mi6 libexec]# ./check_oracle --login mi         ###mi是庫名
OK - dummy login connected
[root@mi6 libexec]# ./check_oracle --cache mi system mi123 80 90       ###mi是庫名,system是資料庫使用者,mi123是system使用者密碼
mi OK - Cache Hit Rates: 99.95% Lib -- 99.39% Buff|lib=99.95%;90;80;0;100 buffer=99.39%;90;80;0;100
[root@mi6 libexec]# ./check_oracle --tablespace mi system mi123 ERY 90 80  ###mi是庫名,system是資料庫使用者,mi123是system使用者密碼,ERY是表空間要大寫 
mi : LOTTERY OK - .30% used [ 10216 / 10240 MB available ]|LOTTERY=.30%;80;90;0;100
3、修改 /usr/local/nagios/etc/nrpe.cfg 檔案。加入以下內容:
command[check_oracle_tns]=/usr/local/nagios/libexec/check_oracle --tns mi
command[check_oracle_db]=/usr/local/nagios/libexec/check_oracle --db mi1
command[check_oracle_login]=/usr/local/nagios/libexec/check_oracle --login mi
command[check_oracle_cache]=/usr/local/nagios/libexec/check_oracle --cache mi system mi123 80 90
command[check_oracle_tablespace]=/usr/local/nagios/libexec/check_oracle --tablespace mi system mi123 ERY 90 80


4、配置完成後,重啟 xinetd 服務。
service xinetd restart




監控端配置
1、可能會出現的錯誤,如果被監控端配置完後,監控端使用如下命令,出現如下錯誤;
[root@mi3 ~]# /usr/local/nagios/libexec/check_nrpe -H 172.16.10.18 -c check_oracle_tns   ###172.16.10.18為資料庫的IP
NRPE: Command 'check_oracle_tns' not defined
解決方法:
由於nrpe是在root使用者下面啟動的,需要在oracle使用者下啟動。
如果在nagios的web管理頁面中出現錯誤提示:Status Information:Cannot determine ORACLE_HOME for sid servername 也同樣是這個問題。
root使用者關掉服務
[root@mi6 libexec]#  ps aux|grep nrpe
root      7559  0.0  0.0  61204   752 pts/4    S+   17:24   0:00 grep nrpe
nagios   23647  0.0  0.0  39988  1136 ?        Ss   Oct29   0:00 /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
[root@mi6 libexec]# kill -9 23647
[root@mi6 libexec]#  ps aux|grep nrpe
root      7597  0.0  0.0  61204   756 pts/4    S+   17:25   0:00 grep nrpe
oracle使用者開啟服務
[oracle@mi6 bin]$ /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
[oracle@mi6 bin]$ exit
[root@mi6 libexec]#  ps aux|grep nrpe
oracle    7600  0.0  0.0  39988  1140 ?        Ss   17:25   0:00 /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
root      7607  0.0  0.0  61204   756 pts/4    S+   17:25   0:00 grep nrpe
檢視
[root@mi3 ~]# /usr/local/nagios/libexec/check_nrpe -H 172.16.10.18 -c check_oracle_tns
OK - reply time 0 msec from mi




2、修改oracle主機的配置檔案
[root@mi3 hosts]# cd /usr/local/nagios/etc/objects/hosts
[root@mi3 hosts]# vi oracleRAC1.cfg
define host {
use linux-server
host_name oracleRAC1
alias Oracle 11g 
address 172.16.10.18 
}   
define service { 
use generic-service 
host_name oracleRAC1 
service_description TNS Check
check_command check_nrpe!check_oracle_tns 
}  
define service { 
use generic-service 
host_name oracleRAC1 
service_description DB Check 
check_command check_nrpe!check_oracle_db 
}   
define service { 
use generic-service
host_name oracleRAC1 
service_description Login Check 
check_command check_nrpe!check_oracle_login
}   
define service {  
use generic-service 
host_name oracleRAC1
service_description Cache Check
check_command check_nrpe!check_oracle_cache 
}  
define service {  
use generic-service 
host_name oracleRAC1
service_description Tablespace Check
check_command check_nrpe!check_oracle_tablespace
}




重啟nagios
service nagios restart




[root@mi3 hosts]# vi oracleRAC2.cfg 
define host {
use linux-server
host_name oracleRAC2
alias Oracle 11g
address 172.16.10.19
}
define service {
use generic-service
host_name oracleRAC2
service_description TNS Check
check_command check_nrpe!check_oracle_tns
}
define service {
use generic-service
host_name oracleRAC2
service_description DB Check
check_command check_nrpe!check_oracle_db
}
define service {
use generic-service
host_name oracleRAC2
service_description Login Check
check_command check_nrpe!check_oracle_login
}
define service {
use generic-service
host_name oracleRAC2
service_description Cache Check
check_command check_nrpe!check_oracle_cache
}
define service {
use generic-service
host_name oracleRAC2
service_description Tablespace Check
check_command check_nrpe!check_oracle_tablespace
}










測試
[root@mi7 etc]# /usr/local/nagios/libexec/check_oracle --tns mi
OK - reply time 10 msec from mi
[root@mi7 etc]# /usr/local/nagios/libexec/check_oracle --db mi2
mi2 OK - 1 PMON process(es) running
[root@mi7 etc]# /usr/local/nagios/libexec/check_oracle --login mi
OK - dummy login connected
[root@mi7 etc]# /usr/local/nagios/libexec/check_oracle --cache mi system mi123 80 90
mi OK - Cache Hit Rates: 99.97% Lib -- 99.65% Buff|lib=99.97%;90;80;0;100 buffer=99.65%;90;80;0;100
[root@mi7 etc]# /usr/local/nagios/libexec/check_oracle --tablespace mi system mi123 LOTTERY 90 80
mi : LOTTERY OK - .30% used [ 10216 / 10240 MB available ]|LOTTERY=.30%;80;90;0;100

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29819001/viewspace-1321607/,如需轉載,請註明出處,否則將追究法律責任。

相關文章