zoukankan      html  css  js  c++  java
  • Zabbix+Orabbix监控oracle数据库表空间

      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 添加主机

    主机名称必须要和配至文件中的databaseLst 中的名称一致

    03.添加oracle 模板

     

    四、验证

     
     
     
     
     
     
     
     

    五、监控库的大小

    01.配置query.props

    默认按照上面的步骤就差不多了,但是你导入模板之后就会发现监控项目不全,如dbsize及dbfilesize这些类目,orabbix默认情况下未开启数据库大小,需要配置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.添加内容如图所示

    注释:语句过长的话要用 来分隔
     
    这个时候就可以启动orabbix服务了
    systemctl restart orabbix
    检查服务ps aux |grep orabbix|wc -l 如果等于2就说明启动那个成功了

    04.查看日志看是否有报错

    /opt/orabbix/logs/orabbix.log
     
     

    六、表空间监控的优化

    01、自定义SQL检查

     
    Orabbix提供了表空间的监控,监控项对应的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 
     这个SQL会返回93%满的表空间信息,而对应这个监控项,orabbix也定义了触发器,因为监控项的返回值是文本,而没有满足条件的记录时返回字符串“none“,所以监控项对应的触发器会检查返回值开头是不是none,如果不是,就报警,这样,用户除了收到预警信息,还能从返回值的具体值中看到具体时哪个表空间快满了。
    当然,大部分时间监控项会返回none,所以我们无法画出正常未满的表空间的空间占用时间曲线。只有超过93%慢时,我们才知道具体的占用情况。

     02、测试

    把值调为5的触发效果
     

     

    官方文档

    http://www.smartmarmot.com/wiki/index.php/Orabbix

  • 相关阅读:
    localtime 和 localtime_r 的区别
    mysql1130远程连接没有权限的解决方法
    pthread_create
    GDB Core,gdb 调试大全,core文件调试
    非root用户 如何将cscope安装到指定目录,vim74安装
    linux查看网络链接状况命令netstat
    在Linux系统如何让程序开机时自动启动
    Linux开机启动程序详解
    u盘出现大文件无法复制的解决
    用JSON报的一个错误java.lang.ClassNotFoundException: org.apache.commons.lang.exception.NestableRuntimeExcep
  • 原文地址:https://www.cnblogs.com/xuewenlong/p/12801162.html
Copyright © 2011-2022 走看看