专业的编程技术博客社区

网站首页 > 博客文章 正文

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

baijin 2024-08-08 23:01:58 博客文章 138 ℃ 0 评论

上一篇文章,我们已经实现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

监控项原型配置

※ 更新迭代时间,请根据大家的环境要求来配置的。

图形原型配置

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

————————————————

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表