zoukankan      html  css  js  c++  java
  • zabbix对oracle表空间的监控

    [root@oracle scripts]# crontab -l

    * * * * * /home/oracle/oracle_cron.sh

    shell(oracle_cron.sh)

    #!/bin/bash

    source /home/oracle/.bash_profile

    sqlplus -s zabbix/zabbix  > /tmp/tablespace.log<<EOF

    set linesize 300 pagesize 1000

    col "Status"   for a10

    col "Name"     for a25

    col "Type"     for a10

    col "Extent"   for a15

    col "Size (M)" for a20

    col "Used (M)" for a20

    col "Used %"   for a20

    SELECT d.status "Status", d.tablespace_name "Name", d.contents "Type", d.extent_management "Extent",

    TO_CHAR(NVL(a.bytes / 1024 / 1024, 0),'99,999,990') "Size (M)",

    TO_CHAR(NVL(a.bytes - NVL(f.bytes, 0), 0)/1024/1024,'999,999,999') "Used (M)",

    TO_CHAR(NVL((a.bytes -  NVL(f.bytes, 0)) / a.bytes * 100, 0), '990.00') "Used %"

    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')

    UNION ALL

    SELECT d.status         "Status", d.tablespace_name "Name", d.contents "Type", d.extent_management "Extent",

    TO_CHAR(NVL(a.bytes / 1024 / 1024, 0),'99,999,999') "Size (M)",

    TO_CHAR(NVL(t.bytes,0)/1024/1024,'999,999,999') "Used (M)",

    TO_CHAR(NVL(t.bytes / a.bytes * 100, 0), '990.00') "Used %" FROM sys.dba_tablespaces d,

    (select tablespace_name, sum(bytes) bytes from dba_temp_files group by tablespace_name) a, (select

    tablespace_name, sum(bytes_cached) bytes from v\$temp_extent_pool group by tablespace_name) t WHERE

    d.tablespace_name = a.tablespace_name(+) AND d.tablespace_name = t.tablespace_name(+) AND

    d.extent_management like 'LOCAL' AND d.contents like 'TEMPORARY'

    ORDER BY 7;

    EOF

    [root@oracle scripts]# pwd

    /usr/local/zabbix/scripts

    [root@oracle scripts]# ll

    total 12

    -rwxr-xr-x 1 root root 399 Apr  1 02:31 oracle_check.sh

    -rwxr-xr-x 1 root root 387 Apr  1 02:18 oracle_check.sh.bak

    -rwxr-xr-x 1 root root 309 Mar 31 19:11 oracle_discovery.sh

    shell2(oracle_discovery.sh)

    #!/bin/bash

    TABLESPACE=`cat /tmp/tablespace.log |awk '{print$2}'|awk 'NR>3{print}'`

    COUNT=`echo "$TABLESPACE" |wc -l`

    INDEX=0

    echo '{"data":['

    echo "$TABLESPACE" | while read LINE; do

            echo -n '{"{#TABLENAME}":"'$LINE'"}'

            INDEX=`expr $INDEX + 1`

            if [ $INDEX -lt $COUNT ]; then

                    echo ','

            fi

    done

    echo ']}'

    shell3(oracle_check.sh)

    #!/bin/bash

    EQ_DATA="$2"

    ZBX_REQ_DATA_TAB="$1"

    SOURCE_DATA=/tmp/tablespace.log

    case $2 in

      maxmb)        grep -E "$ZBX_REQ_DATA_TAB" $SOURCE_DATA |awk '{print $5*1024*1024}';;

      used)   grep -E "$ZBX_REQ_DATA_TAB" $SOURCE_DATA |awk '{print $6*1024*1024}';;

      autopercent)  grep -E "$ZBX_REQ_DATA_TAB" $SOURCE_DATA |awk '{print $7}';;

      *) echo $ERROR_WRONG_PARAM; exit 1;;

    esac

    exit 0

    echo $1 $2

    检测

    [root@oracle scripts]# ./oracle_check.sh SYSTEM autopercent

    99.95

    [root@oracle scripts]# ./oracle_check.sh USERS maxmb

    5242880

    说明脚本配置成功

    [root@oracle zabbix]# vim etc/zabbix_agentd.conf

    把下面这两行配置加到最后:

    UserParameter=ora.tab.discovery,/usr/local/zabbix/scripts/oracle_discovery.sh

    UserParameter=tablespace[*],/usr/local/zabbix/scripts/oracle_check.sh $1 $2

    zabbix_server端添加discovery模板,之前安装过orabbix,直接在Template_Oracle下的自动发现规则下新建自动发现规则:

    自动发现规则下添加监控原型:

     

    然后在图形原型配置、并将上面的三个原型添加进去:

     

    最后设置触发器:

    (这里是以autopercent为判断条件,>95时产生告警)

    最后重启客户端的zabbix_agent

    修改服务端的zabbix_server.conf的CacheSize至256M

    重启服务端的zabbix_server和orabbix

  • 相关阅读:
    Java 中位移运算符 >>,>>>,<<
    HashMap 源码解读
    CentOS 配置防火墙操作实例(启、停、开、闭端口)
    CentOS 配置防火墙操作实例(启、停、开、闭端口)
    js实现页面重新加载
    js实现页面重新加载
    关于Ajax的技术组成与核心原理
    关于Ajax的技术组成与核心原理
    PHP水印制作
    PHP水印制作
  • 原文地址:https://www.cnblogs.com/tangliyao/p/6769806.html
Copyright © 2011-2022 走看看