使用自定义检查项
ORAchk支持自定义检查项,用户只要按照一定的规则,创建对应的XML配置文件,就可以让ORAchk进行自定义检查。
ORAchk的软件包里面提供了一个sample_user_defined_checks.xml,给出了几个例子,而且有详细的注释,只要按照这个规则,生成user_defined_checks.xml,放在orachk所在的目录,就可以让orachk进行自定义检查了。自定义检查项目前支持两种类型:OS 命令和SQL语句。下面我看一个SQL语句的自定义检查:
这个检查返回空闲空间比例小于10%的表空间的个数,为0是检查通过,不为0是FAIL。
<?xml version="1.0" encoding="UTF-8"?>
<UserDefinedChecks
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="user_defined_checks.xsd"> <!-- Main Tag (root element)-->
<CHECK AUDIT_CHECK_NAME="Tablespace Utilization">
<!-- This check should run on all supported platforms and versions given the platform and version specs below -->
<Oracle_VERSION>*</ORACLE_VERSION>
<PLATFORMS>
<PLATFORM TYPE="*">
<FLAVOR>*</FLAVOR>
</PLATFORM>
</PLATFORMS>
<PARAM_PATH>tbs_ut</PARAM_PATH> <!—注意这里参数值需要和SQL_COMMAND中的返回字符串匹配-->
<SQL_COMMAND> <!—这个SQL返回空闲空间比例小于10的表空间的个数-->
<![CDATA[ select 'tbs_ut = '||count(*) from (select a.tablespace_name,
trunc(sum(a.tots) / 1024 / 1024, 2) Tot_Size_mb,
round(sum(a.sumb) / 1024 / 1024, 2) Tot_Free_mb,
round(sum(a.sumb) * 100 / sum(a.tots), 2) Pct_Free,
round(sum(a.largest) / 1024 / 1024, 2) Max_Free_mb,
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)
where PCT_FREE < 10;]]> <!—注意大于号,小于号,等号都需要替换为XML能够处理的字符-->
</SQL_COMMAND>
<SQL_COMMAND_REPORT>
<![CDATA[select 'Free PCT less 10% TBS = '||count(*) from (select a.tablespace_name,
trunc(sum(a.tots) / 1024 / 1024, 2) Tot_Size_mb,
round(sum(a.sumb) / 1024 / 1024, 2) Tot_Free_mb,
round(sum(a.sumb) * 100 / sum(a.tots), 2) Pct_Free,
round(sum(a.largest) / 1024 / 1024, 2) Max_Free_mb,
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)
where PCT_FREE < 10;]]>
</SQL_COMMAND_REPORT>
<OPERATOR>=</OPERATOR>
<COMPARE_VALUE>0</COMPARE_VALUE> <!—操作符是等号,比较值是0,也就是说SQL返回0,代表pass,否则fail-->
<CANDIDATE_SYSTEMS>*</CANDIDATE_SYSTEMS>
<COMPONENT_DEPENDENCY>RDBMS</COMPONENT_DEPENDENCY>
<DATABASE_MODE>3</DATABASE_MODE> <!— 3代表open,2代表mount,1代表nomount-->
<DATABASE_TYPE>CDB:PDB:NORMAL</DATABASE_TYPE>
<DATABASE_ROLE>PRIMARY</DATABASE_ROLE>
<ALERT_LEVEL>FAIL</ALERT_LEVEL>
<PASS_MSG>The number of Tablespaces which free PCT less 10% is zero</PASS_MSG>
<FAIL_MSG>The number of Tablespaces which free PCT less 10% is not zero</FAIL_MSG>
<BENEFIT_IMPACT>
<![CDATA[ tablespace free pct should be more than 10% ]]>
</BENEFIT_IMPACT>
<RISK>
<![CDATA[ leak of space ]]>
</RISK>
<ACTION_REPAIR>
<![CDATA[ add datafile or resize datafile ]]>
</ACTION_REPAIR>
<LINKS>
<LINK></LINK>
</LINKS>
</CHECK>
<!-- END USER DEFINED CHECKS -->
</UserDefinedChecks>
自定义检查项,可以和其他检查项一起执行,也可以单独执行,单独执行自定义检查项的语法是:
# ./orachk –profile user_defined_checks
下面是自定义检查项报告样例:
如果你觉得这样写XML麻烦,还可以使用CM应用来生成自定义检查项的XML文件,菜单路径:Administration -> “+ Add New User Defined Checks”
定义好后,可以生成XML文件并下载:
不过这个功能并不完善,缺乏必要得有效性检查,如果想不出错,还是要把XML得规则搞清楚,我个人还是比较喜欢手工写XML。