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

周期性健康检查脚本:

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 MAIL_LIST=XXXX@XX.com
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]

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值