自定义SQL检查

Orabbix提供了表空间的监察,监控项对应之SQL:

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%款款时,我们才理解具体的挤占情况。

如想征集并保存更多信息,就得采用由定义查询,方法就是以query.props文件被参加你想检查的SQL,比如我们怀念了解表空间信息,就再说下SQL:

customtbl.Query=select ‘TBL:’||a.tablespace_name||’,’ TBL, \

‘Total Size:’||trunc(sum(a.tots) / 1024 / 1024, 2)||’,’ Tot_Size_mb,
\

‘Free MB:’||round(sum(a.sumb) / 1024 / 1024, 2)||’,’ Tot_Free_mb, \

‘PCT Free:’||round(sum(a.sumb) * 100 / sum(a.tots), 2)||’,’ Pct_Free,
\

‘Max Free MB:’||round(sum(a.largest) / 1024 / 1024, 2)||’,’
Max_Free_mb, \

‘Chunks Free:’||sum(a.chunks)||’,’ Chunks_Free \

from (select tablespace_name, \

0 tots, \

sum(bytes) sumb, \

max(bytes) largest, \

count(*) chunks \

from dba_free_space a \

group by tablespace_name \

union \

select tablespace_name, sum(bytes) tots, 0, 0, 0 \

from dba_data_files \

group by tablespace_name) a \

group by a.tablespace_name

customtbl.NoDataFound=none

然后以orabbix对应的模板被丰富这个监控项customtbl就得了,下面时由最新数据菜单查看的SQL的回结果:

hg0088皇冠 1

本,我们若召开更的剖析及出示,就需要运用别的工具或开发工具来开了,这个就非是当下首文章讨论的克了。

导入模板

当orabbix的软件包中来4各级模板文件,导入下面途中这模板文件就足以了,包含了其他具有模板文件的内容。

hg0088皇冠 2

适用Orabbix

当zabbix界面上配置数据库监控时,要留心,orabbix是管每个数据库都安排成一个“主机”的,这块看正在有接触别扭,而且,注意在布置主机时,名称一定要和config.props文件被布局的数据库名称一致,比如自己这里就是是DB1:

hg0088皇冠 3

前说了,这个“主机”的地方可以任由写,因为被监督之主机端不需一定生agent,但是为了方便管理,我觉得还是写上Oracle主机的地方比较好。

概念了主机后,就足以适用模板被预定义的督查项、触发器和图纸了。

按图片:

hg0088皇冠 4

hg0088皇冠 5

论最简易的检查数据库适用可用之触发器:

hg0088皇冠 6

当然,对许触发器的动作要待好安排。

Orabbix介绍

监控Oracle数据库我们用设置第三正提供的Zabbix插件,我们事先测试于显赫的Orabbix,http://www.smartmarmot.com/product/orabbix/

hg0088皇冠 7

自布局架构图上足见到,orabbix是通过JDBC去老是为监督数据库的,其实不是要以数量库主机上安装Agent,而运作orabbix的主机,可以是Zabbix
Server,也足以是数据库主机和zabbix
server之外的任性一玉主机,为了测试好,我们以orabbix安装在Zabbix
Server上。

下载软件及安装服务

Ø 下充斥 Orabbix ,上传到您的 Zabbix Server

Ø unzip 软件到这个目录: /opt/orabbix

Ø 安装服务:

Ø 复制启动脚本

#cp /opt/orabbix/init.d/orabbix /etc/init.d/orabbix

Ø 运行权限:

#chmod +x /etc/init.d/orabbix

#chmod +x /opt/orabbix/run.sh

Ø #chkconfig –add orabbix

树立监督用户与授权

CREATE USER ZABBIX

IDENTIFIED BY welcome1

DEFAULT TABLESPACE SYSTEM

TEMPORARY TABLESPACE TEMP

PROFILE DEFAULT

ACCOUNT UNLOCK;

REM 2 Roles for ZABBIX

GRANT CONNECT TO ZABBIX;

GRANT RESOURCE TO ZABBIX;

ALTER USER ZABBIX DEFAULT ROLE ALL;

REM 5 System Privileges for ZABBIX

GRANT SELECT ANY TABLE TO ZABBIX;

GRANT CREATE SESSION TO ZABBIX;

GRANT SELECT ANY DICTIONARY TO ZABBIX;

GRANT UNLIMITED TABLESPACE TO ZABBIX;

GRANT SELECT ANY DICTIONARY TO ZABBIX;

倘是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;

导入模板

每当orabbix的软件包里来4各级模板文件,导入下面途中这模板文件就好了,包含了另外兼具模板文件之情节。

hg0088皇冠 8

下载软件及安装服务

Ø 下充斥 Orabbix ,上传到您的 Zabbix Server

Ø unzip 软件到此目录: /opt/orabbix

Ø 安装服务:

Ø 复制启动脚本

#cp /opt/orabbix/init.d/orabbix /etc/init.d/orabbix

Ø 运行权限:

#chmod +x /etc/init.d/orabbix

#chmod +x /opt/orabbix/run.sh

Ø #chkconfig –add orabbix

起监督用户与授权

CREATE USER ZABBIX

IDENTIFIED BY welcome1

DEFAULT TABLESPACE SYSTEM

TEMPORARY TABLESPACE TEMP

PROFILE DEFAULT

ACCOUNT UNLOCK;

REM 2 Roles for ZABBIX

GRANT CONNECT TO ZABBIX;

GRANT RESOURCE TO ZABBIX;

ALTER USER ZABBIX DEFAULT ROLE ALL;

REM 5 System Privileges for ZABBIX

GRANT SELECT ANY TABLE TO ZABBIX;

GRANT CREATE SESSION TO ZABBIX;

GRANT SELECT ANY DICTIONARY TO ZABBIX;

GRANT UNLIMITED TABLESPACE TO ZABBIX;

GRANT SELECT ANY DICTIONARY TO ZABBIX;

假设是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;

 

 

适用Orabbix

在zabbix界面上布置数据库监控时,要小心,orabbix是拿每个数据库都布置成一个“主机”的,这块看在有硌别扭,而且,注意在布局主机时,名称一定要是和config.props文件中安排的数据库名称相同,比如我此虽是DB1:

hg0088皇冠 9

面前说了,这个“主机”的地址可以管写,因为受监督的主机端不待肯定有agent,但是以方便管理,我以为要写及Oracle主机的地址比较好。

概念了主机后,就可以适用模板被预定义的监察项、触发器和图表了。

比如图片:

hg0088皇冠 10

hg0088皇冠 11

遵最简便易行的检查数据库适用可用之触发器:

hg0088皇冠 12

本,对承诺触发器的动作要待团结配置。

Orabbix介绍

监控Oracle数据库我们需要安装第三正提供的Zabbix插件,我们事先测试于显赫的Orabbix,http://www.smartmarmot.com/product/orabbix/

hg0088皇冠 13

从布局架构图上可见到,orabbix是由此JDBC去老是于监控数据库的,其实不是要以数据库主机上安装Agent,而运行orabbix的主机,可以是Zabbix
Server,也足以是数据库主机和zabbix
server之外的自由一华主机,为了测试好,我们用orabbix安装在Zabbix
Server上。

Orabbix不足

开始测试,感觉orabbix有2沾明显缺欠:

1.
深受监控数据库信息一旦依次个写进配置文件,如果数据库个数较多,管理会比较费心

2.
吃监督数据库的账号信息是描写在部署文件被,而且口令是光天化日存储,有很死之安全隐患

  1. 针对RAC的支持还是格外初级
修改orabbix配置文件

#cd /opt/orabbix/conf

#cp config.props.sample config.props

根据实际的配备情况修改文件,比如:

#comma separed list of Zabbix servers

ZabbixServerList=ZabbixServer1

ZabbixServer1.Address=192.168.0.41 ##Zabbix服务器地址

ZabbixServer1.Port=10051 ##Zabbix服务器端口

#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=DB1,DB2,DB3 ##数据库列表,名称随便起

#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

DB1.Url=jdbc:oracle:thin:@192.168.0.31:1521:test1 ##数据库连接串

DB1.User=zabbix ##督查数据库用户称

DB1.Password=welcome1 ##督查数据库口令

保留配置文件,然后再度开orabbix。

修改orabbix配置文件

#cd /opt/orabbix/conf

#cp config.props.sample config.props

据悉实际的布局情况修改文件,比如:

#comma separed list of Zabbix servers

ZabbixServerList=ZabbixServer1

ZabbixServer1.Address=192.168.0.41 ##Zabbix服务器地址

ZabbixServer1.Port=10051 ##Zabbix服务器端口

#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=DB1,DB2,DB3 ##数据库列表,名称随便从

#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

DB1.Url=jdbc:oracle:thin:@192.168.0.31:1521:test1 ##数据库连接串

DB1.User=zabbix ##监理数据库用户称

DB1.Password=welcome1 ##监督数据库口令

封存配置文件,然后还开orabbix。

Orabbix不足

千帆竞发测试,感觉orabbix有2触及明确瑕疵:

1.
被监控数据库信息要挨个个写进配置文件,如果数据库个数较多,管理会比较麻烦

2.
给监督数据库的账号信息是形容以布置文件被,而且口令是当面存储,有好要命的安全隐患

  1. 本着RAC的支持还是好初级
自定义SQL检查

Orabbix提供了表空间的督查,监控项对应之SQL:

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%慢性时,我们才懂具体的占情况。

只要想征集并保存更多信息,就用采取从定义查询,方法就是于query.props文件被参加你想检查的SQL,比如我们怀念了解表空间信息,就再说下SQL:

customtbl.Query=select ‘TBL:’||a.tablespace_name||’,’ TBL, \

‘Total Size:’||trunc(sum(a.tots) / 1024 / 1024, 2)||’,’ Tot_Size_mb,
\

‘Free MB:’||round(sum(a.sumb) / 1024 / 1024, 2)||’,’ Tot_Free_mb, \

‘PCT Free:’||round(sum(a.sumb) * 100 / sum(a.tots), 2)||’,’ Pct_Free,
\

‘Max Free MB:’||round(sum(a.largest) / 1024 / 1024, 2)||’,’
Max_Free_mb, \

‘Chunks Free:’||sum(a.chunks)||’,’ Chunks_Free \

from (select tablespace_name, \

0 tots, \

sum(bytes) sumb, \

max(bytes) largest, \

count(*) chunks \

from dba_free_space a \

group by tablespace_name \

union \

select tablespace_name, sum(bytes) tots, 0, 0, 0 \

from dba_data_files \

group by tablespace_name) a \

group by a.tablespace_name

customtbl.NoDataFound=none

然后以orabbix对应之模板被丰富这个监控项customtbl就得了,下面时由新型数据菜单查看的SQL的回结果:

hg0088皇冠 14

当,我们若做更的解析和出示,就待利用别的工具要开发工具来开了,这个就未是这首文章讨论的限定了。

相关文章