Zabbix监控Oracle数据库表空间,并配置邮件告警

Oracle表空间监控

核心数据库10.100.0.20和21表空间已经修改完成,可以正常监控使用率和大小,并邮件告警通知。

修改Oracle数据库表空间监控

创建表空间信息收集脚本:

vim /home/oracle/scripts/check_tablespace.sh

脚本内容如下:

#!/bin/bash# tablespace usagep checksource ~/.bash_profilefunction check {sqlplus -S "/ as sysdba" <<  EOFset numwidth 20set linesize 200set pagesize 200spool /tmp/ora_tablespace.txt select aa.tablespace_name,        round(bb.maxs, 2) "MAX(G)",        round(aa.usd, 2) "USED(G)",        round((bb.maxs - aa.usd) , 2) "FREE(G)",        round(aa.usd / bb.maxs * 100, 2) "USED%"   from (Select b.Tablespace_Name, (b.Bytes - Nvl(a.Bytes, 0)) "USD"           From (select tablespace_name, sum(bytes) bytes                   from Dba_Free_Space                  group by tablespace_name) a,                (select tablespace_name, sum(bytes) bytes                   from Dba_Data_Files                  group by tablespace_name) b          Where b.tablespace_name = a.tablespace_name(+)         -- and b.tablespace_name='MAXIMO_DATA'         ) aa,        (select tablespace_name,                sum(case                      when maxbytes = 0 then                       user_bytes                      else                       maxbytes                    end) "MAXS"           from dba_data_files         -- where tablespace_name='MAXIMO_DATA'          group by tablespace_name          order by tablespace_name) bb  where aa.tablespace_name = bb.tablespace_name and aa.tablespace_name not like '%UNDO%'  order by 5 desc, 1;spool offset linesize 100set pagesize 100spool /tmp/ora_autex.txtselect tablespace_name,autoextensible from dba_data_files;spool offquitEOF};check &>/dev/null

赋予执行权限

chmod +x /home/oracle/scripts/check_tablespace.sh

配置计划任务(oracle用户)

*/5 * * * * /home/oracle/scripts/check_tablespace.sh

手动执行脚本并查看结果

表空间脚本执行结果

自动发现脚本内容如下:

# cat discovery_oracle_tablespace.sh#!/bin/bash#zabbix discovery oracle tablespacetable_spaces=(`cat /tmp/ora_tablespace.txt | sed -e "1,3d" -e "/^$/d" -e "/selected/d" | awk '{print $1}'`)length=${#table_spaces[@]} printf "{n"printf 't'""data"":[""for ((i=0;i<$length;i++))do    printf ""ntt{""    printf """"{#TABLESPACE_NAME}"":""${table_spaces[$i]}""}""    if [ $i -lt $[$length-1] ];then        printf ""

                                                        

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2020年10月1日
下一篇 2020年10月1日

相关推荐