这是一个用来监控Oracle Data Guard环境下从主库到备库的重做日志传输和应用情况的nagios插件。在我们所维护的系统环境中,如果有data guard环境的数据库系统,可以使用此插件监控data guard的运行状态。建议设置为每小时运行一次。该插件测试结果显示其执行时间有数秒钟,请注意。
1、技术关键点:
在主库上检查v$archived_log视图中归档日志的最新归档日志和最新应用时间来判断日志传输和应用状态。使用的SQL如下:
with t_standby as (select dest_id, applied, max(first_time) as first_time from v\\$archived_log group by dest_id, applied) select dest_id,round(nvl(archived_gap,0)) as archived_gap,round(nvl(applied_gap,0)) applied_gap from ( select (SELECT ${P3} FROM DUAL) as dest_id, 60*24 * ((select first_time from t_standby where dest_id = 1) - (select max(first_time) from t_standby where dest_id = ${P3})) as archived_gap, 60*24 * ((select max(first_time) from t_standby where dest_id =${P3}) - (select min(first_time) from t_standby where dest_id = ${P3})) as applied_gap from dual );
2、源代码见附件
3、使用格式
check_oracle_standby.sh --standby_dest"
4、使用示例
例如,监控主库xxdb的实例xxdb1的log_archive_dest_2的日志传输和应用情况
/usr/local/nagios/libexec/check_oracle_standby.sh --standby_dest xxdb1 2 archived_gap 10 applied_gap 10
结果如下:
standby OK:db:xxdb1 log_archive_dest_2 archived_gap:0mins applied_gap:0mins
例如:监控主库yydb的实例yydb1的log_archive_dest_2和log_archive_dest_3的日志传输和应用情况
/usr/local/nagios/libexec/check_oracle_standby_dest.sh --standby_dest yydb1 2 archived_gap 10 applied_gap 1500
结果如下:
standby OK:db:yydb1 log_archive_dest_2 archived_gap:0mins applied_gap:1475mins
注意,log_archive_dest_2执行的standby节点的日志应用延迟了1440分钟,所以这里看到延迟时间较长。
/usr/local/nagios/libexec/check_oracle_standby_dest.sh --standby_dest yydb1 3 archived_gap 10 applied_gap 10
结果如下:
standby CRITICAL:db:yydb1 log_archive_dest_3 archived_gap:0mins applied_gap:46mins