使用zabbix監控oracle數據庫需要借助第三方的插件,目前使用較多的是orabbix。目前維護到了1.2.3版本。關於oracle自帶的監控項目有以下幾個:
DB Version (i.e. Validity of package)數據庫版本
Archiving (Archive log production with trend analysis)歸檔文件
Event Waits (Files I/O, single block read, multi-block read, direct path read, SQLNet Messages, Control file I/O, Log Write)等待的事件
Hit Ratio (Hit Ratio on Triggers, Tables/Procedures, SQL Area, Body)
Logical I/O (Server performance on Logical I/O of: Current Read, Consistent Read, Block Change)邏輯I/O
Physical I/O (Redo Writes, Datafile Writes, Datafile Reads)物理I/O
PGA
SGA (In particular; Fixed Buffer, Java Pool, Large Pool, Log Buffer, Shared Poolm Buffer Cache)
Shared Pool (Pool Dictionary Cache, Pool Free Memory, Library Chache, SQL Area, MISC.)共享池
Pin Hit Ratio (Oracle library cache pin are caused by contention with the library cache, the area used to store SQL executables for re-use)
Sessions / Processes**會話數和進程數**
Sessions (Active Sessions, Inactive Sessions, System Sessions)
DBSize/DBFileSize (DBSize size of database really used space and of Filesize)數據庫大小
1.節點:zabbix服務端和oracle數據庫兩個節點。
2.安全設置:為了實驗起見,關閉selinux和iptables
3.獲取安裝包:
orabbix-1.2.3.zip
4.下載安裝jdk(x86_64),在oracle的官網可以下載,配置好JAVA_HOME等環境變量。
1.創建訪問數據庫的用戶並進行相關授權
使用oracle的管理員用戶登錄oracle數據庫:
[oracle@server ~]$ sqlplus sys/oracle@hybris as sysdba
創建zabbix用戶並且授予其相關權限:
(1)創建用戶
CREATE USER ZABBIX IDENTIFIED BY ZABBIX DEFAULT TABLESPACE SYSTEM TEMPORARY TABLESPACE TEMP PROFILE DEFAULT ACCOUNT UNLOCK;
(2)授予權限
GRANT CONNECT TO ZABBIX; GRANT RESOURCE TO ZABBIX; ALTER USER ZABBIX DEFAULT ROLE ALL; GRANT SELECT ANY TABLE TO ZABBIX; GRANT CREATE SESSION TO ZABBIX; GRANT SELECT ANY DICTIONARY TO ZABBIX; GRANT UNLIMITED TABLESPACE TO ZABBIX; GRANT SELECT ANY DICTIONARY TO ZABBIX;
上述是給zabbix較高權限,如果只是為了滿足orabbix自帶的監控項目,可以只授予zabbix如下權限:
CREATE USER ZABBIX IDENTIFIED BY ZABBIX DEFAULT TABLESPACE USERS TEMPORARY TABLESPACE TEMP PROFILE DEFAULT ACCOUNT UNLOCK; GRANT ALTER SESSION TO ZABBIX; GRANT CREATE SESSION TO ZABBIX; GRANT CONNECT TO ZABBIX; ALTER USER ZABBIX DEFAULT ROLE ALL; GRANT SELECT ON V_$INSTANCE TO ZABBIX; GRANT SELECT ON DBA_USERS TO ZABBIX; GRANT SELECT ON V_$LOG_HISTORY TO ZABBIX; GRANT SELECT ON V_$PARAMETER TO ZABBIX; GRANT SELECT ON SYS.DBA_AUDIT_SESSION TO ZABBIX; GRANT SELECT ON V_$LOCK TO ZABBIX; GRANT SELECT ON DBA_REGISTRY TO ZABBIX; GRANT SELECT ON V_$LIBRARYCACHE TO ZABBIX; GRANT SELECT ON V_$SYSSTAT TO ZABBIX; GRANT SELECT ON V_$PARAMETER TO ZABBIX; GRANT SELECT ON V_$LATCH TO ZABBIX; GRANT SELECT ON V_$PGASTAT TO ZABBIX; GRANT SELECT ON V_$SGASTAT TO ZABBIX; GRANT SELECT ON V_$LIBRARYCACHE TO ZABBIX; GRANT SELECT ON V_$PROCESS TO ZABBIX; GRANT SELECT ON DBA_DATA_FILES TO ZABBIX; GRANT SELECT ON DBA_TEMP_FILES TO ZABBIX; GRANT SELECT ON DBA_FREE_SPACE TO ZABBIX; GRANT SELECT ON V_$SYSTEM_EVENT TO ZABBIX;
如果當前的oracle版本是11g的話,還需要添加如下的語句開放acl的訪問控制,否則在監控的過程中有部份內容無法正常顯示(例於數據庫版本,數據庫文件大小等)。
exec dbms_network_acl_admin.create_acl(acl => 'resolve.xml',description => 'resolve acl', principal =>'ZABBIX', is_grant => true, privilege => 'resolve'); exec dbms_network_acl_admin.assign_acl(acl => 'resolve.xml', host =>'*'); commit;
授權完成後可以使用zabbix用戶登錄測試下:
[oracle@server ~]$ sqlplus zabbix/zabbix SQL*Plus: Release 11.2.0.1.0 Production on Mon Nov 7 20:11:12 2016 Copyright (c) 1982, 2009, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options SQL>
2.解壓安裝包orabbix,設置配置文件,啟動服務
獲得orabbix-1.2.3.zip解壓包,這裡需要注意的事必須解壓到/opt/orabbix目錄下(由啟動服務腳本決定),所以需要創建該目錄:
[root@server opt]# mkdir /opt/orabbix/
解壓到該目錄:
[root@server orabbix]# unzip orabbix-1.2.3.zip
得到配置文件/opt/orabbix/conf/config.props:
[root@server conf]# cp /opt/orabbix/conf/config.props.sample /opt/orabbix/conf/config.props
修改配置文件:
[root@server conf]# grep "^[^#]" config.props ZabbixServerList=ZabbixServer1,ZabbixServer2 ZabbixServer1.Address=IP ZabbixServer1.Port=port ZabbixServer2.Address=ip ZabbixServer2.Port=port OrabbixDaemon.PidFile=./logs/orabbix.pid OrabbixDaemon.Sleep=300 OrabbixDaemon.MaxThreadNumber=100 DatabaseList=hybristest DatabaseList.MaxActive=10 DatabaseList.MaxWait=100 DatabaseList.MaxIdle=1 hybristest.Url=jdbc:oracle:thin:@10.211.33.177:1521:HYBRIS hybristest.User=zabbix hybristest.Password=zabbix hybristest.MaxActive=10 hybristest.MaxWait=100 hybristest.MaxIdle=1 hybristest.QueryListFile=./conf/query.props
這裡非常需要注意的一點是DatabaseList這個參數“DatabaseList=hybristest”,他所代表的含義是:被監控服務器的名稱。必須要和被監控服務器的名稱一致,要不會導致及時數據可以從數據庫中獲取到,但是依然無法顯示到zabbix的界面上。
ZabbixServerList=ZabbixServer1,ZabbixServer2
ZabbixServer1.Address=IP
ZabbixServer1.Port=port
ZabbixServer2.Address=ip
ZabbixServer2.Port=port
其中ZabbixServerList列舉的是zabbix服務端的名稱,然後指定其ip和端口即可。
將啟動腳本拷貝到/etc/init.d/目錄中,並且授予相關文件的可執行權限:
[root@server init.d]# cp /opt/orabbix/init.d/orabbix /etc/init.d/ [root@server init.d]# chmod +x /etc/init.d/orabbix /opt/orabbix/run.sh
啟動orabbix服務並且觀察日志信息:
[root@server init.d]# /etc/init.d/orabbix start [root@server init.d]# vim /opt/orabbix/logs/orabbix.log 2016-11-07 17:01:44,508 [main] INFO Orabbix - Starting Orabbix Version 1.2.3 2016-11-07 17:01:44,518 [main] INFO Orabbix - Orabbix started with pid:26807 2016-11-07 17:01:44,518 [main] INFO Orabbix - PidFile -> ./logs/orabbix.pid 2016-11-07 17:01:44,642 [main] INFO Orabbix - DB Pool created: org.apache.commons.dbcp.datasources.SharedPoolDataSource@c2e1f26 2016-11-07 17:01:44,642 [main] INFO Orabbix - URL=jdbc:oracle:thin:@10.211.33.177:1521:HYBRIS 2016-11-07 17:01:44,642 [main] INFO Orabbix - maxPoolSize=10 2016-11-07 17:01:44,643 [main] INFO Orabbix - maxIdleSize=1 2016-11-07 17:01:44,643 [main] INFO Orabbix - maxIdleTime=1800000ms 2016-11-07 17:01:44,643 [main] INFO Orabbix - poolTimeout=100 2016-11-07 17:01:44,643 [main] INFO Orabbix - timeBetweenEvictionRunsMillis=-1 2016-11-07 17:01:44,643 [main] INFO Orabbix - numTestsPerEvictionRun=3 2016-11-07 17:01:45,065 [main] INFO Orabbix - Connected as ZABBIX 2016-11-07 17:01:45,066 [main] INFO Orabbix - --------- on Database -> HYBRIS 2016-11-07 17:01:45,394 [pool-1-thread-1] INFO Orabbix - Done with dbJob on database hybristest QueryList elapsed time 299 ms 2016-11-07 17:02:45,123 [pool-1-thread-2] INFO Orabbix - Done with dbJob on database hybristest QueryList elapsed time 16 ms 2016-11-07 17:03:45,356 [pool-1-thread-3] INFO Orabbix - Done with dbJob on database hybristest QueryList elapsed time 233 ms 2016-11-07 17:04:45,149 [pool-1-thread-4] INFO Orabbix - Done with dbJob on database hybristest QueryList elapsed time 13 ms 2016-11-07 17:05:45,387 [pool-1-thread-5] INFO Orabbix - Done with dbJob on database hybristest QueryList elapsed time 234 ms 2016-11-07 17:06:45,181 [pool-1-thread-6] INFO Orabbix - Done with dbJob on database hybristest QueryList elapsed time 9 ms 2016-11-07 17:07:45,404 [pool-1-thread-7] INFO Orabbix - Done with dbJob on database hybristest QueryList elapsed time 214 ms 2016-11-07 17:08:45,217 [pool-1-thread-8] INFO Orabbix - Done with dbJob on database hybristest QueryList elapsed time 14 ms 2016-11-07 17:09:45,435 [pool-1-thread-9] INFO Orabbix - Done with dbJob on database hybristest QueryList elapsed time 221 ms 2016-11-07 17:10:45,234 [pool-1-thread-10] INFO Orabbix - Done with dbJob on database hybristest QueryList elapsed time 9 ms 2016-11-07 17:11:45,491 [pool-1-thread-11] INFO Orabbix - Done with dbJob on database hybristest QueryList elapsed time 250 ms 2016-11-07 17:12:45,266 [pool-1-thread-12] INFO Orabbix - Done with dbJob on database hybristest QueryList elapsed time 12 ms 2016-11-07 17:13:45,510 [pool-1-thread-13] INFO Orabbix - Done with dbJob on database hybristest QueryList elapsed time 240 ms 2016-11-07 17:14:45,289 [pool-1-thread-14] INFO Orabbix - Done with dbJob on database hybristest QueryList elapsed time 6 ms 2016-11-07 17:15:45,502 [pool-1-thread-15] INFO Orabbix - Done with dbJob on database hybristest QueryList elapsed time 201 ms 2016-11-07 17:16:45,321 [pool-1-thread-16] INFO Orabbix - Done with dbJob on database hybristest QueryList elapsed time 7 ms 2016-11-07 17:17:45,542 [pool-1-thread-17] INFO Orabbix - Done with dbJob on database hybristest QueryList elapsed time 221 ms 2016-11-07 17:18:45,339 [pool-1-thread-18] INFO Orabbix - Done with dbJob on database hybristest QueryList elapsed time 6 ms 2016-11-07 17:19:45,546 [pool-1-thread-19] INFO Orabbix - Done with dbJob on database hybristest QueryList elapsed time 196 ms
沒有任何的報錯,說明服務是正常啟動的。
查看服務端口:
[root@server init.d]# netstat -anutlp | grep ora tcp 0 0 10.211.33.177:51461 10.211.33.177:1521 ESTABLISHED 3117/ora_pmon_HYBRI tcp 0 0 :::59335 :::* LISTEN 3149/ora_d000_HYBRI tcp 0 0 ::ffff:10.211.33.177:1521 ::ffff:172.20.0.26:39631 ESTABLISHED 11609/oracleHYBRIS tcp 0 0 ::ffff:10.211.33.177:1521 ::ffff:10.211.33.177:22366 ESTABLISHED 26824/oracleHYBRIS tcp 0 0 ::ffff:10.211.33.177:1521 ::ffff:172.20.0.26:44515 ESTABLISHED 24901/oracleHYBRIS udp 0 0 :::11898 :::* 3145/ora_mmon_HYBRI udp 0 0 ::1:12305 :::* 3151/ora_s000_HYBRI udp 0 0 ::1:42515 :::* 3149/ora_d000_HYBRI udp 0 0 ::1:15670 :::* 3117/ora_pmon_HYBRI
注意:需要說明的是,orabbix可以部署在oracle所在的節點上。
3.在zabbix前台操作界面添加模板和設置監控節點
(1)首先需要導入orabbix的模板文件:
[root@server template]# pwd /opt/orabbix/template [root@server template]# ls Orabbix_export_full.xml Orabbix_export_graphs.xml Orabbix_export_items.xml Orabbix_export_triggers.xml
在zabbix控制界面導入該模板:
選擇模板文件Orabbix_export_full.xml:
得到Template_Oracle模板:
(2)將模板導入到被監控的節點:
(3)在graphs中查看相關視圖內容:
shared pool<喎?http://www.2cto.com/kf/ware/vc/" target="_blank" class="keylink">vcD4NCjxwPjxpbWcgYWx0PQ=="這裡寫圖片描述" src="http://www.2cto.com/uploadfile/Collfiles/20161108/20161108093904118.png" title="\" />
PGA
Session/Process
Logical IO
還有很多視圖就不一一列舉了.
1.orabbix配置文件出現異常,首先需要清楚每個參數的含義,然後再進行配置;
2.數據無法獲取(通過查看orabbix的日志文件可以看到報錯),orabbix查詢oracle數據庫的用戶權限不夠,需要授予足夠的權限;
3.zabbix界面無法得到數據,如果可以確保上面一項是可以從數據庫中獲得數據的話,則需要查看conf.props文件中指定的DatabaseList是否正確(必須是zabbix控制台上的主機名)。
orabbix出了自身支持的監控項,根據用戶的需求,還可以進行個性化的設置,這個交給大家自己發揮。