虚拟化容器,大数据,DBA,中间件,监控。

Zabbix 通过pyora监控oracle

08 07月
作者:admin|分类:监控安全

Zabbix 通过pyora监控oracle

1.oracle客户端的安装

从oracle官方网站上下载客户端,devel和sqlplus程序或者从以下网址下载 http://pan.uu456.com/s/1mgx8Fsk

以root用户安装

rpm –ivh oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm

rpm –ivh oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm

rpm –ivh oracle-instantclient11.2-sqlplus-11.2.0.4.0-1.x86_64.rpm

vim /root/.bashrc 添加

export ORACLE_HOME=/usr/lib/oracle/11.2/client64

export LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client64/lib

export TNS_ADMIN=/usr/lib/oracle/11.2/client64/network/admin

export PATH=$PATH:$ORACLE_HOME/bin

设置好环境变量之后执行

source /root/.bashrc

创建文件 /etc/ld.so.conf.d/oracle.conf添加

/usr/lib/oracle/11.2/client64/lib

执行命令 ldconfig

创建连接文件

在ORACLE_HOME目录下创建以下目录network/admin,并创建文件tnsnames.ora,内容如下:

vim /usr/lib/oracle/11.2/client64/network/admin/tnsnames.ora

orcl =

(DESCRIPTION =

(ADDRESS_LIST =

(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.10)(PORT = 1521)) )

(CONNECT_DATA =

(SERVICE_NAME = orcl)

)

)

测试

执行

[root@Monitor ~]# sqlplus system/admin@orcl

SQL*Plus: Release 11.2.0.4.0 Production on Thu May 8 14:25:07 2014

Copyright (c) 1982, 2013, Oracle. All rights reserved.

Connected to:

Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production

With the Partitioning, OLAP and Data Mining options

SQL>

测试成功!

注:

sqlplus: error while loading shared libraries: libsqlplus.so: cannot open shared object file: No such file or directory

说明环境变量没有生效!

SQL> conn system/oracle@depdb1

ERROR:

ORA-21561: OID generation failed

检查自己的/etc/hosts文件,修改/etc/hosts

127.0.0.1 localhost localhost.localdomain

192.168.0.10 orcl orcl

192.168.0.110 Monitor Monitor

2. python库cx_Oracle的安装

下载http://jaist.dl.sourceforge.net/project/cx-oracle/5.1.1/cx_Oracle-5.1.1-1.src.rpm或者从http://pan.uu456.com/s/1gdeLYEJ

[root@devel ~]# rpm -ivh cx_Oracle-5.1.1-1.src.rpm

1:cx_Oracle

########################################### [100%]

[root@devel ~]# cd ~/rpmbuild/SPECS

[root@devel ~]# ORACLE_HOME=/usr/lib/oracle/11.2/client64/ rpmbuild -ba cx_Oracle.spec

[root@devel ~]# cd ../RPMS/x86_64

[root@devel ~]# rpm -ivh cx_Oracle-5.1.1-1.x86_64.rpm

Preparing...

########################################### [100%]

1:cx_Oracle

########################################### [100%]

注:

因为我的系统的python版本是2.6 所以要将Oracle.spec中的python2.4改为python2.6

3.pyora下载安装

利用pyora监控oracle数据库需要用到cx_Oracle和oracle客户端,安装pyora之前请确保前两个软件安装完毕

下载pyora

[root@Monitor ~]# cd /tmp/

[root@Monitor tmp]#git clone https://github.com/bicofino/Pyora.git

Cloning into 'Pyora'...

remote: Counting objects: 17, done.

remote: Compressing objects: 100% (14/14), done.

remote: Total 17 (delta 2), reused 16 (delta 1)

Unpacking objects: 100% (17/17), done.

然后在/etc/zabbix_agentd.conf 中添加

UserParameter=pyora[*],/home/zabbix/scripts/pyora.py --username $1 --password $2 --address $3 --database $4 $5 $6 $7 $8

我是通过zabbix-server端的zabbix-agent 监控其他机器的oracle数据库,导入模板zabbix-template/Pyora.xml到你的主机

{$ADDRESS} 192.168.0.1

{$DATABASE} MY_ORACLE_DATABASE

{$USERNAME} zabbix

{$PASSWORD} zabbix

{$ARCHIVE} VGDATA

{$HIGH} 90



本次介绍如何使用zabbix监控oracle,主要使用pyora这个python脚本来监控,具体地址可以参考 https://github.com/bicofino/Pyora

我的zabbix版本为2.0.6,oracle为11g

下面是部分效果图

1、 Oracle/Active user count

wKiom1OwxRrz6WsuAAOCu-LClPw228.jpg 2、 Oracle/Bytes sent and received via SQL*Net to Client

wKioL1OwxQiDkLjDAARQNSee3vk907.jpg 3、Oracle/Database CPU Time Ratio

wKioL1OwxSSCmK_RAANriO5B7mM372.jpg 4、Oracle/Database Wait Time Ratio

wKiom1OwxW6Rje8bAAM7fCyHASQ264.jpg 5、Oracle/Deadlocks

wKioL1OwxVryQFcrAAOXxUbv3pU686.jpg 6、Oracle/Disk sorts ratio

wKioL1OwxXWjSzFAAANbg3psXC4593.jpg 7、Oracle/Hard parse ratio

wKioL1OwxZHCfICPAANriQ1sFwc972.jpg 8、Oracle/Query

wKiom1Oww6qBjcMHAAROrmPPzV0816.jpg 9、Oracle/Size of all datafiles

wKiom1Oww9TjsgT_AAOeZIsbRZI942.jpg 10、Oracle/Size of user data (without temp)

wKioL1Oww9zhonuoAAP5HY5X6Hc252.jpg 11、Oracle/Table scan rows gotten

wKiom1OwxD_TDuJoAAOpdf3gz9k502.jpg 12、   Oracle/Tablespace Use On SYSTEM

wKiom1OwxHqgd1ITAANsgNN0zUw473.jpg 13、Oracle/Uptime

wKioL1OwxH2B10lNAANQldI64ro285.jpg 14、Oracle/User Transaction Per Sec

wKiom1OwxNrhNFAuAAN8TCJAyYA399.jpg 15、Oracle listen 1521 port

wKiom1OwxPbzp30vAAN9Abehxkc616.jpg

报警方面:

1、oracle的1521端口是否监听

2、 表空间使用率

3、 Oracle 在线时间

1、修改zabbix_agentd.conf文件

在zabbix_agentd.conf最后添加以下内容

UserParameter=pyora[*],/usr/local/zabbix/bin/pyora.py --username $1 --password $2 --address $3 --database $4 $5 $6 $7 $8

2、 把附件的pyora.py的脚本放到/usr/local/zabbix/bin里,然后给与755权限,并修改用户与组为zabbix(注意,我的pyora.py脚本修改了一些内容,比如如果出现None的返回,我修改为0了,如果需要使用原来的脚本,请去 https://github.com/bicofino/Pyora 里面下载)

3、安装依赖

确保本机python在2.6以上

安装cx_Oracle与argparse

easy_install cx_Oracle
easy_install argparse

4、在oracle里创建监控oracle账户

CREATE USER ZABBIX IDENTIFIED BY 'zabbix' DEFAULT TABLESPACE SYSTEM TEMPORARY TABLESPACE TEMP PROFILE DEFAULT ACCOUNT UNLOCK;
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;
GRANT SELECT ON V_$SESSION TO ZABBIX;
GRANT SELECT ON V_$SYSTEM_EVENT TO ZABBIX;
GRANT SELECT ON V_$EVENT_NAME TO ZABBIX;
GRANT SELECT ON V_$RECOVERY_FILE_DEST TO ZABBIX;
ps -ef|grep zabbix|grep -v grep|awk '{print $2}'|xargs kill -9
/usr/local/zabbix/sbin/zabbix_agentd -c /usr/local/zabbix/conf/zabbix_agentd.conf

1、模板导入

把Template memcached Auto Discovery导入到zabbix里(模板在附件)。

2、主机关联模板

在添加主机,并且关联模板的时候,选择“宏”

wKioL1OwyluwX_DaAACGZjedafI155.jpg

wKioL1OwypvRnj9mAADaLpFDgkM624.jpg

这样就能出图了,注意自动发现规则的时间为3600秒。


浏览3094 评论0
返回
目录
返回
首页
Configuring a Squid Server to authenticate off Active Directory WebSphere集群+Oracle+代理方案