Zabbix监控系统系列之十五:自动发现Oracle表空间并监控

25 篇文章 66 订阅

======= 系列目录 =======
Zabbix监控系统系列之一 : Server部署
Zabbix监控系统系列之二 : 初始化配置
Zabbix监控系统系列之三 :版本升级
Zabbix监控系统系列之四:Agent监控Windows客户端
Zabbix监控系统系列之五:SNMP监控Windows客户端
Zabbix监控系统系列之六:EMAIL警告配置
Zabbix监控系统系列之七:VMware虚拟化监控
Zabbix监控系统系列之八:日志监控
Zabbix监控系统系列之九:监控网络设备指定接口流量
Zabbix监控系统系列之十:自动发现配置
Zabbix监控系统系列之十一:拓扑图绘制
Zabbix监控系统系列之十二:SNMP Traps主动告警
Zabbix监控系统系列之十三:SNMP Mibs库加载
Zabbix监控系统系列之十四:Oracle监控
Zabbix监控系统系列之十五:自动发现Oracle表空间并监控
======================

上一篇文章,我们已经实现Zabbix通过Orabbix 1.2.3对Oracle进行必要的监控。许多情况之下,我们还需要对表空间运用有一个宏观的了解并在必要时对其进行扩展。

网上许多都是基于Linux环境的自动发现Oracle表空间并监控,我客户有许多是基于Windows环境,固本文以Windows环境的Oracle表空间自动发现为基础。
※ 本文也是一种Zabbix对业务系统监控的方法思路,大家可以类推到其他业务系统。
在这里插入图片描述

在这里插入图片描述

[实施步骤]
1.设置表空间信息定时输出
tablespace.sql

set feedback off
set linesize 140 pagesize 10000
col "Status"   for a10
col "Name"     for a25
col "Type"     for a10
col "Extent"   for a15
col "Size (M)" for a15
col "Used (M)" for a15
col "Used %"   for a20
spool tablespace.log
SELECT d.status "Status", d.tablespace_name "Name", d.contents "Type", d.extent_management "Extent",
TO_CHAR(NVL(a.bytes / 1024 / 1024, 0),'99999990') "Size (M)",
TO_CHAR(NVL(a.bytes - NVL(f.bytes, 0), 0)/1024/1024,'999999999') "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),'99999999') "Size (M)",
TO_CHAR(NVL(t.bytes,0)/1024/1024,'999999999') "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;
spool off
exit

tablespace.bat

sqlplus / as sysdba @tablespace.sql

※ 此处各位需要注意安全性问题,我提供思路而已。

Windows计划任务(1分钟执行一次,5分钟执行一次,10分钟执行一次,大家自己考虑)
在这里插入图片描述
输出结果参考:
在这里插入图片描述
2.设置自动发现脚本
AutodiscoverTBS.bat

@echo off
Setlocal ENABLEDELAYEDEXPANSION

type c:\Scripts\tablespace.log | awk "{print$2}" | awk "NR>3{print}" > tmp.txt

SET /a INDEX=3
for /F %%i in ('type c:\Scripts\tablespace.log ^| find /v /c ""') do ( set COUNT=%%i)
echo {"data":[ 
for /F "usebackq eol=# tokens=1,2 delims==" %%T in (tmp.txt) do (
		SET /a INDEX+=1
		if !INDEX! NEQ %COUNT% (
		 echo {"{#TABLENAME}":"%%T"},
		) else (
		 echo {"{#TABLENAME}":"%%T"}]}
		) 

)
del tmp.txt

3.设置截取表空间指定参数值脚本
脚本中,我用到awk命令。此命令在Linux系统环境原生命令,但Windows并没有类似的命令。可以在sourceforge下载awk for windows版本,下载地址参考http://gnuwin32.sourceforge.net/packages/gawk.htm

CheckORATBS.bat

@echo off

if /I %2 EQU max (goto max)

if /I %2 EQU used (goto used)

if /I %2 EQU autopercent (goto autopercent)

:max
type c:\scripts\tablespace.log | find "%1" | awk "{print $5}"
goto Exit

:used
type c:\scripts\tablespace.log | find "%1" | awk "{print $6}"
goto Exit

:autopercent
type c:\scripts\tablespace.log | find "%1" | awk "{print $7}"
goto Exit

:exit
exit

4.Zabbix Agent用户自定义参数配置
zabbix_agentd.win.conf配置文件追加参数:
UserParameter=ora.tab.discovery,C:\scripts\AutodiscoverTBS.bat
UserParameter=tablespace[*],C:\scripts\CheckORATBS.bat $1 $2
在这里插入图片描述

5.Zabbix Agent服务重启

6.Zabbix Server服务台验证用户自定义参数
zabbix_get -s 192.168.0.94 -k “ora.tab.discovery”
zabbix_get -s 192.168.0.94 -k “tablespace[USERS autopercent]”
zabbix_get -s 192.168.0.94 -k “tablespace[USERS max]”
zabbix_get -s 192.168.0.94 -k “tablespace[USERS used]”

7.设置监控模板
Name 名称 TablespaceDiscovery
Type 类型 Zabbix agent
Key 键值 ora.tab.discovery
Update interval 更新迭代 3600s

在这里插入图片描述
监控项原型配置
在这里插入图片描述
※ 更新迭代时间,请根据大家的环境要求来配置的。
在这里插入图片描述
图形原型配置
在这里插入图片描述

在这里插入图片描述

整个过程非常简单,不过思路非常重要!此方法给大家提供一个业务系统自定义监控项的方法。

评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值