结合zabbix监控DG同步状态

从三方面监控DG状态

1、监控应用日志是否延迟超过15个归档日志,超过就输出数字1到/tmp/dg_status_monitor.log文件

2、监控是否存在MRP进程,若不存在,就输出数字1到/tmp/dg_status_monitor.log文件

3、监控gv$managed_standby的status字段是否为WAIT_FOR_GAP,若是,就输出数字1到/tmp/dg_status_monitor.log文件

4、若都不满足以上条件,则证明当前DG同步正常,输出数字0到/tmp/dg_status_monitor.log文件,zabbix读取文件/tmp/dg_status_monitor.log,若为1则告警。

#!/bin/bash
seq1=`su - oracle -c "sqlplus -S / as sysdba" <<'EOF'
set heading off
set pagesize 0;
set feedback off;
set verify off;
set echo off;
select a.max_sequence-b.max_applied_sequence from (select max(sequence#) max_sequence from v$archived_log) a, (select max(sequence#) max_applied_sequence  from v$archived_log where applied='YES') b;
quit;
EOF`

seq2=`ps -ef | grep mrp0 | grep -v grep | wc -l`

seq3=`su - oracle -c "sqlplus -S / as sysdba" <<'EOF'
set heading off
set pagesize 0;
set feedback off;
set verify off;
set echo off;
select status from gv$managed_standby where process='MRP0';
quit;
EOF`

if [ $seq1 -lt 15 ]&&[ $seq2 -eq 1 ]&&[ $seq3 != "WAIT_FOR_GAP" ]; then
    echo 0 > /tmp/dg_status_monitor.log
else
    echo 1 > /tmp/dg_status_monitor.log
fi

你可能感兴趣的:(DataGuard)