orabbix是一个用来监控Oracle数据库性能的zabbix插件工具,通过安装在被监控服务器上客户端上收集数据并传给zabbix服务器端,然后通过调用图形显示.
它是通过JDBC监控数据库的
能对以下进行监控:
- 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)
- Physical I/O (Redo Writes, Datafile Writes, Datafile Reads)
- 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 Server -->这里我使用的是zabbix-3.2.6
- Java Runtime Environment -->我用的是dk1.7.0_80
2. 安装orabbix
2.1 下载orabbix
http://sourceforge.net/projects/orabbix/files/orabbix-1.2.3.zip/download
mkdir /opt/orabbix mv orabbix-1.2.3.jar /opt/orabbix cd /opt/orabbix unzip orabbix-1.2.3.zip
2.2 添加服务启动脚本,和相关脚本赋权
cp /opt/orabbix/init.d/orabbix /etc/init.d/ chmod u+x /etc/init.d/orabbix chmod u+x /opt/orabbix/run.sh
chkconfig --add orabbix
chkconfig orabbix on
run.sh还需要进行修改,将java改成你的JDK中java命令的绝对路径
/usr/java/jdk1.7.0_80/bin/java -Duser.language=en -Duser.country=US -Dlog4j.configuration=./conf/log4j.properties -cp $(for i in lib/*.jar ; do echo -n $i: ; done).:./orabbix-1.2.3.jar com.smartmarmot.orabbix.bootstrap start ./conf/config.props &
2.3 在oracle数据库上创建zabbix用户,并授权
CREATE USER zabbix IDENTIFIED BY zabbix DEFAULT TABLESPACE SYSTEM TEMPORARY TABLESPACE TEMP PROFILE DEFAULT ACCOUNT UNLOCK; – 2 Roles for ZABBIX GRANT CONNECT TO ZABBIX; GRANT RESOURCE TO ZABBIX; ALTER USER ZABBIX DEFAULT ROLE ALL; – 5 System Privileges for ZABBIX 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;
如果需要严格的权限控制,可以执行如下脚本
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;
如果是oracle11g用户还需要开放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;
可以运行下面的语句确保上面的没有问题
select utl_inaddr.get_host_name('127.0.0.1') from dual;
2.4 创建配置文件config.props
cd /opt/orabbix/conf/ cp /opt/orabbix/conf/config.props.sample config.props
配置参数
[root@lanmp conf]# cat config.props|grep -v '^#|^$' #comma separed list of Zabbix servers ZabbixServerList=ZabbixServer1 ZabbixServer1.Address=192.168.0.95 ZabbixServer1.Port=10051 #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=oracledb #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 oracledb.Url=jdbc:oracle:thin:@192.168.0.92:1521:dbsrv1 oracledb.User=zabbix oracledb.Password=zabbix #Those values are optionals if not specified Orabbix is going to use the general values oracledb.MaxActive=10 oracledb.MaxWait=100 oracledb.MaxIdle=1 oracledb.QueryListFile=./conf/query.props
PS:
DatabaseList中放的是被监控的数据库主机名,该名称要和zabbix server界面中的机器名称保持一致
2.5 启动orabbix
[root@lanmp orabbix]# service orabbix start Starting Orabbix service:
查看启动的进程
[root@lanmp orabbix]# ps aux |grep orabbix root 25572 35.0 2.3 1295872 45084 pts/2 Sl 15:54 0:00 /usr/java/jdk1.7.0_80/bin/java -Duser.language=en -Duser.country=US -Dlog4j.configuration=./conf/log4j.properties -cp lib/commons-codec-1.4.jar:lib/commons-dbcp-1.4.jar:lib/commons-lang-2.5.jar:lib/commons-logging-1.1.1.jar:lib/commons-pool-1.5.4.jar:lib/hsqldb.jar:lib/log4j-1.2.15.jar:lib/ojdbc6.jar:.:./orabbix-1.2.3.jar com.smartmarmot.orabbix.bootstrap start ./conf/config.props root 25585 0.0 0.0 103316 844 pts/2 S+ 15:54 0:00 grep orabbix
3. WEB界面配置
3.1 导入模板文件
导入模板。模板在/opt/orabbix/template.
Orabbix_export_full.xml 全部导入(图表 监控项 触发器)
Orabbix_export_graphs.xml 图表
Orabbix_export_items.xml 监控项
Orabbix_export_triggers.xml 触发器
模板-->导入
如果导入失败,需要将orabbix的4个xml里面的<group>TEMPLATES</group>改成<group>TEMPLATES_ORACLE</group>,然后重新导入import即可。
3.2 将被监控的主机关联模板
你会发现有一些监控项dbfilesize,dbsize没有值,这是因为/opt/orabbix/conf/query.props文件没有把这两个加入进查询的List下面,可以从query.props.sample把这两项复制进去
在QueryList最后面加上dbfilesize,dbsize
然后在文件末尾加入:
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')
结果演示: