Orabbix 是設計用來為 zabbix 監控 Oracle 數據庫的插件,它提供多層次的監控,包括可用性和服務器性能指標。
它提供了從眾多 oracle 實例采集數據的有效機制,進而提供此信息的監控和性能指標。然后,您可以利用的 zabbix 的報告功能為收集的所有數據,並提供分析。目前的發行版中包含了一組預先定義的模板,包括從初始部署警報和圖形功能。然而,這些可以進行微調,以滿足您的需求和數據/監控要求
一簡介
系統環境:
Linux Centos 7.4
3.10.0-693.21.1.el7.x86_64
Zabbix版本:zabbix 3.4.7
Orabbix 監控什么?
數據庫版本
歸檔日志與生產趨勢分析
觸發器,表/過程等命中率
邏輯 I/O 性能
物理 I/O 性能
PGA
SGA
共享池
Sessions
數據庫大小
表空間
Orabbix
二、zabbix server 端操作
需要安裝在同構通信、遠程Orabbix的server上
01 下載安裝Orabbix
http://www.smartmarmot.com/product/orabbix/download/
雲盤鏈接:
https://pan.baidu.com/s/1Q9ktCS3mHUdqL7IPShNVGQ
1.1 創建目錄
mkdir -p /opt/orabbix mv orabbix-1.2.3.zip /opt/orabbix cd /opt/orabbix
1.2 解壓orabbix
unzip orabbix-1.2.3.zip
1.3 創建orabbix備份
cp conf/config.props.sample conf/config.props
1.4 啟動程序拷貝至/etx/init.d/
cp init.d/orabbix /etc/init.d/
1.5 分配權限
chmod +x /etc/init.d/orabbix
chmod +x /opt/orabbix/run.sh
1.6 安裝jdk
yum install java -y
02 創建數據庫賬號
oracle 服務器端操作
登錄 oracle
su - oracle # 切換到 oracle 用戶 sqlplus /nolog # 不連接任何數據庫 conn /as sysdba # 用sysdba 登陸 或 conn 用戶名/密碼 select instance_name from v$instance; # 查看實例
2.1 創建Oracle賬號
首先我們需要在被監控的Oracle上面創建一個賬號,用於zabbix的數據獲取,在oracle的sqlplus里面執行
CREATE USER ZABBIX IDENTIFIED BY "zabbix" DEFAULT TABLESPACE SYSTEM TEMPORARY TABLESPACE TEMP PROFILE DEFAULT ACCOUNT UNLOCK;
2.2 賦予角色權限
GRANT CONNECT TO ZABBIX;
GRANT RESOURCE TO ZABBIX;
ALTER USER ZABBIX DEFAULT ROLE ALL;
2.3 賦予系統權限
GRANT CREATE SESSION TO ZABBIX;
GRANT SELECT ANY DICTIONARY TO ZABBIX;
GRANT UNLIMITED TABLESPACE TO ZABBIX;
GRANT SELECT ANY DICTIONARY TO ZABBIX;
2.4 如果我們的數據庫是Oracle 11g,我們還需要執行下面的語句
注釋:官方文檔是需要執行這個語句的,測試沒有執行也一樣可以用,目前沒有發現問題(可參考)
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;
03 修改配置文件
編輯剛剛生成的config.props文件
zabbix server 端操作
vim /opt/orabbix/conf/config.props ## 修改后內容如下 ## #comma separed list of Zabbix servers ZabbixServerList=ZabbixServer ZabbixServer.Address=192.168.2.145 #zabbix server IP地址 ZabbixServer.Port=10051 #端口 ZabbixServer2.Address=IP_ADDRESS_OF_ZABBIX_SERVER ZabbixServer2.Port=PORT_OF_ZABBIX_SERVER #pidFile OrabbixDaemon.PidFile=./logs/orabbix.pid #frequency of item's refresh OrabbixDaemon.Sleep=300 #MaxThreadNumber should be >= than the number of your databases OrabbixDaemon.MaxThreadNumber=100 #put here your databases in a comma separated list DatabaseList=192.168.2.142 #名稱與該機在 zabbix中監控的主機名稱保持一致 #Configuration of Connection pool #if not specified Orabbis is going to use default values (hardcoded) #Maximum number of active connection inside pool DatabaseList.MaxActive=10 #The maximum number of milliseconds that the pool will wait #(when there are no available connections) for a connection to be returned #before throwing an exception, or <= 0 to wait indefinitely. DatabaseList.MaxWait=100 DatabaseList.MaxIdle=1 #define here your connection string for each database 192.168.2.142.Url=jdbc:oracle:thin:@192.168.2.142:1521:orcl # 需要 jdk 環境,因為這里是通過 JDBC 連接的, #orcl 為數據庫實例名稱 192.168.2.142.User=ZABBIX # 用來監控 oracle 數據庫的用戶名和密碼,需要在 oracle 中創建並賦予一定的權限 192.168.2.142.Password=ZABBIX #Those values are optionals if not specified Orabbix is going to use the general values 192.168.2.142.MaxActive=10 192.168.2.142.MaxWait=100 192.168.2.142.MaxIdle=1 192.168.2.142.QueryListFile=./conf/query.props #DB2.Url=jdbc:oracle:thin:@server2.domain.example.com:<LISTENER_PORT>:DB2 #DB2.User=zabbix #DB2.Password=zabbix_password #DB2.QueryListFile=./conf/query.props #DB3.Url=jdbc:oracle:thin:@server3.domain.example.com:<LISTENER_PORT>:DB3 #DB3.User=zabbix #DB3.Password=zabbix_password #DB3.QueryListFile=./conf/query.props
注:
以上端口號為與Zabbix Server通訊的端口,我這里是將Orabbix與Zabbix server 裝在同一台機器上的,如果不在同一台機器,那裝Orabbix的機器需要先裝Zabbix Agent,否則數據將無法傳送到Zabbix Server。
注:
ZabbixServerList:可以設置多個,用","進行分割;
DatabaseList:可以設置多個被監控的Oracle數據庫服務器,用","進行分割,該名稱要和zabbix server界面中的Host name保持一致,該配置文件中后續所引用的設定都以該名稱為准。
關於JDBC 可參考:
Oracle = jdbc:oracle:thin:@<host>:<LISTENER_PORT>:<instance> PostgreSQL = jdbc:postgresql://<host>:<port>/<database> MS Sql Server = jdbc:jtds:sqlserver://<host>:<port>/<instancename> MySQL Server = jdbc:mysql://[host:port],[host:port].../[database] DB2 = jdbc:db2://<servername>:<port>/<installation>
啟動服務 /etc/init.d/orabbix start 或 systemctl start orabbix
三、zabbix web 端操作
01 導入模板
模板在/opt/orabbix/template/ 目錄下面,全部導入zabbix web 即可
02 添加主機

03.添加oracle 模板


四、驗證










五、監控庫的大小
01.配置query.props
cp /opt/orabbix/conf/query.props /opt/orabbix/conf/query.props.bak
vi /opt/orabbix/conf/query.props
在QueryList=類目下增加dbfilesize,dbsize,如圖所示
02.然后在該文件的末尾添加
dbfilesize.Query=select to_char(sum(bytes/1024/1024/10), 'FM99999999999999990') retvalue from dba_data_files dbsize.Query=SELECT to_char(sum( NVL(a.bytes/1024/1024/10 - NVL(f.bytes/1024/1024/10, 0), 0)), 'FM99999999999999990') retvalue \ FROM sys.dba_tablespaces d, \ (select tablespace_name, sum(bytes) bytes from dba_data_files group by tablespace_name) a, \ (select tablespace_name, sum(bytes) bytes from dba_free_space group by tablespace_name) f \ WHERE d.tablespace_name = a.tablespace_name(+) AND d.tablespace_name = f.tablespace_name(+) \ AND NOT (d.extent_management like 'LOCAL' AND d.contents like 'TEMPORARY')
用以定義查詢dbfilesize,dbsize的SQL語句
03.添加內容如圖所示

04.查看日志看是否有報錯


六、表空間監控的優化
01、自定義SQL檢查
vim /opt/orabbix/conf/query.props tbl_space.Query=SELECT * FROM ( \ select '- Tablespace ->',t.tablespace_name ktablespace, \ '- Type->',substr(t.contents, 1, 1) tipo, \ '- Used(MB)->',trunc((d.tbs_size-nvl(s.free_space, 0))/1024/1024) ktbs_em_uso, \ '- ActualSize(MB)->',trunc(d.tbs_size/1024/1024) ktbs_size, \ '- MaxSize(MB)->',trunc(d.tbs_maxsize/1024/1024) ktbs_maxsize, \ '- FreeSpace(MB)->',trunc(nvl(s.free_space, 0)/1024/1024) kfree_space, \ '- Space->',trunc((d.tbs_maxsize - d.tbs_size + nvl(s.free_space, 0))/1024/1024) kspace, \ '- Perc->',decode(d.tbs_maxsize, 0, 0, trunc((d.tbs_size-nvl(s.free_space, 0))*100/d.tbs_maxsize)) kperc \ from \ ( select SUM(bytes) tbs_size, \ SUM(decode(sign(maxbytes - bytes), -1, bytes, maxbytes)) tbs_maxsize, tablespace_name tablespace \ from ( select nvl(bytes, 0) bytes, nvl(maxbytes, 0) maxbytes, tablespace_name \ from dba_data_files \ union all \ select nvl(bytes, 0) bytes, nvl(maxbytes, 0) maxbytes, tablespace_name \ from dba_temp_files \ ) \ group by tablespace_name \ ) d, \ ( select SUM(bytes) free_space, \ tablespace_name tablespace \ from dba_free_space \ group by tablespace_name \ ) s, \ dba_tablespaces t \ where t.tablespace_name = d.tablespace(+) and \ t.tablespace_name = s.tablespace(+) \ order by 8) \ where kperc > 93 \ and tipo <>'T' \ and tipo <>'U' tbl_space.NoDataFound=none

02、測試


官方文檔
http://www.smartmarmot.com/wiki/index.php/Orabbix