36. Script to perform a regular scheduled healthcheck of a live GoldenGate confguration

版权声明:本文为原创文章,转载请标明出处。 https://blog.csdn.net/zwjzqqb/article/details/81166791

周期性健康检查脚本:

1° 依据《CentOS6u9 简单邮件告警部署》部署告警邮件

2° 配置脚本:

cat >/tmp/status_report.sh<<EOF
#!/bin/bash
# Written by Ankur Gupta
# Modified and Note by Vincent
source ~/.bash_profile
# Oracle相关的环境变量均写入.bash_profile中
export GG_HOME=/ggs
# export [email protected]
export REPORT_FILE=/tmp/status_report.txt
export HOSTNAME=\$(hostname)
# 查看所有进程状态 
list_all(){
echo 'info *'|./ggsci &>/tmp/all_processes.txt
}
# 查看单个进程状态
status(){
echo "status \$1"|./ggsci &>/tmp/proc_stat.txt
}
# 查看单个进程延迟
lag(){
echo "lag \$1"|./ggsci &>/tmp/lag.txt
}
# main
printf "%-19s \t %-8s \t %-10s %-19s \n" Time Process Status Lag > \$REPORT_FILE
echo "===========================================================================" >> \$REPORT_FILE
cd \$GG_HOME
list_all
for process in \$(egrep 'EXTRACT|REPLICAT' /tmp/all_processes.txt | awk {' print \$2 '})
do
  status \$process
  export STATUS=\$(grep \$process /tmp/proc_stat.txt | awk -F':' {'print \$2'} | tr -d ' ')
  if [ \$STATUS == 'RUNNING' ]; then
    lag \$process
    export EOF=\$(grep EOF /tmp/lag.txt| wc -l)
    if [ \$EOF -eq 1 ]; then
      LAG_STATUS="Reached End of File"
    else
      export LAG_STATUS=\$(grep "Last record lag" /tmp/lag.txt | awk -F':' {'print \$2'} | tr -d '.')
    fi
  else
    export LAG_STATUS="CHECK PROCESS STATUS"
  fi
  Timestamp=\$(date "+%F %T:%S")
  printf "%-19s \t %-8s \t %-10s %-19s \n" "\$Timestamp" "\$process" "\$STATUS" "\$LAG_STATUS" >> \$REPORT_FILE
done
# Email the Report to the Mailing List
# mail -s "Daily GoldenGate Replication Status Report for \$HOSTNAME" \$MAIL_LIST < \$REPORT_FILE
EOF
chmod +x /tmp/status_report.sh

这里写图片描述

3° 配置周期任务:

crontab -l>/tmp/crontab.tmp
echo -e '\n# OGG Daily Check'>>/tmp/crontab.tmp
echo '0 0 * * * /tmp/status_report.sh'>>/tmp/crontab.tmp
cat /tmp/crontab.tmp |crontab
rm -rf /tmp/crontab.tmp

4° 注意:

该脚本包含邮件发送操作,但是一般部署OGG的主机是不能上网公网的,因此邮件发送操作需要再考虑其他方法

[TOC]

猜你喜欢

转载自blog.csdn.net/zwjzqqb/article/details/81166791