归档—监控ORACLE数据库告警日志
ORACLE的告警日志里面包含许多有用的信息,尤其是一些ORACLE的ORA错误信息,所以有必要及时归档、监控数据库告警日志的ORA错误,及时提醒数据库管理员DBA处理这些错误信息,那么我们首先来看看告警日志的内容片断:
Thread 1 advanced to log sequence 37749 (LGWR switch)Current log# 6 seq# 37749 mem# 0: /u01/oradata/SCM2/redo06.log Thu Jun 27 15:02:30 2013 Thread 1 advanced to log sequence 37750 (LGWR switch)Current log# 2 seq# 37750 mem# 0: /u01/oradata/SCM2/redo02.log Thu Jun 27 15:13:43 2013 Thread 1 advanced to log sequence 37751 (LGWR switch)Current log# 3 seq# 37751 mem# 0: /u01/oradata/SCM2/redo03.log Thu Jun 27 15:25:30 2013 Thread 1 advanced to log sequence 37752 (LGWR switch)Current log# 4 seq# 37752 mem# 0: /u01/oradata/SCM2/redo04.log Thu Jun 27 15:32:20 2013 ORA-00060: Deadlock detected. More info in file /u01/app/oracle/admin/SCM2/bdump/scm2_s001_14052.trc. Thu Jun 27 15:35:05 2013 Thread 1 advanced to log sequence 37753 (LGWR switch)Current log# 5 seq# 37753 mem# 0: /u01/oradata/SCM2/redo05.log Thu Jun 27 15:43:11 2013 Thread 1 advanced to log sequence 37754 (LGWR switch)Current log# 1 seq# 37754 mem# 0: /u01/oradata/SCM2/redo01.log Thu Jun 27 15:49:58 2013 Thread 1 advanced to log sequence 37755 (LGWR switch)Current log# 6 seq# 37755 mem# 0: /u01/oradata/SCM2/redo06.log Thu Jun 27 16:01:25 2013 Thread 1 advanced to log sequence 37756 (LGWR switch)Current log# 2 seq# 37756 mem# 0: /u01/oradata/SCM2/redo02.log Thu Jun 27 16:12:14 2013 Thread 1 advanced to log sequence 37757 (LGWR switch)Current log# 3 seq# 37757 mem# 0: /u01/oradata/SCM2/redo03.log Thu Jun 27 16:24:10 2013 Thread 1 advanced to log sequence 37758 (LGWR switch)
View Code
归档告警日志文件
告警日志文件如果不加管理的话,那么文件会持续增长,有时候文件会变得非常大,不利于读写。一般建议将告警日志按天归档,归档文件保留三个月(视情况而定),下面来看看将告警日志文件归档的两个Shell脚本:
- #*************************************************************************
- # FileName :alert_log_archive.sh
- #*************************************************************************
- # Author :Kerry
- # CreateDate :2013-07-02
- # blogs :www.cnblogs.com/kerrycode
- # Description :this script is made the alert log archived every day
- #*************************************************************************
- #! /bin/bash
- date=`date +%Y%m%d`
- alert_log_path="$ORACLE_BASE/admin/$ORACLE_SID/bdump"
- alert_log_file="alert_$ORACLE_SID.log"
- alert_arc_file="alert_$ORACLE_SID.log""."${date}
- cd ${alert_log_path};
- if [ ! -e "${alert_log_file}" ]; then
- echo "the alert log didn't exits, please check file path is correct!";
- exit;
- fi
- if [ -e ${alert_arc_file} ];then
- echo "the alert log file have been archived!"
- else
- cat ${alert_log_file} >> ${alert_arc_file}
- cat /dev/null > ${alert_log_file}
- fi
其实脚本1和脚本差别不大,仅仅是mv与cat >>的区别
- #*************************************************************************
- # FileName :alert_log_archive.sh
- #*************************************************************************
- # Author :Kerry
- # CreateDate :2013-07-02
- # blogs :www.cnblogs.com/kerrycode
- # Description :this script is made the alert log archived every day
- #*************************************************************************
- #! /bin/bash
- date=`date +%Y%m%d`
- alert_log_path="$ORACLE_BASE/admin/$ORACLE_SID/bdump"
- alert_log_file="alert_$ORACLE_SID.log"
- alert_arc_file="alert_$ORACLE_SID.log""."${date}
- cd ${alert_log_path};
- if [ ! -e "${alert_log_file}" ]; then
- echo "the alert log didn't exits, please check file path is correct!";
- exit;
- fi
- if [ -e ${alert_arc_file} ];then
- echo "the alert log file have been archived!"
- else
- mv ${alert_log_file} ${alert_arc_file}
- cat /dev/null > ${alert_log_file}
- fi
然后在crontab定时任务里面加上下面语句,每天23点59对告警日志进行归档。
[oracle@DB-Server scripts]$ crontab -l
# the alert log archived every day Add by kerry 2013-07-02
59 23 * * * /home/oracle/scripts/alert_log_archive.sh >/dev/null 2>$1
细心的朋友可能已经发现上面的脚本、配置错误了,我在部署测试的过程中,是指定二十分钟执行一次,但是等了四十分钟,发现定时任务一次都没有执行,手工执行上面脚本是完全没有问题的,最后仔细的检查一遍,居然发现悲剧的发现时自己一时粗心将&符号写成了$,真是很二的一个错误
59 23 * * * /home/oracle/scripts/alert_log_archive.sh >/dev/null 2>$1
59 23 * * * /home/oracle/scripts/alert_log_archive.sh >/dev/null 2>&1
接下来测试发现脚本执行有问题,在crontab 里执行该shell脚本时,获取不到ORACLE的环境变量,这是因为crontab环境变量问题,Crontab的环境默认情况下并不包含系统中当前用户的环境。所以,你需要在shell脚本中添加必要的环境变量的设置,修改的脚本如下:
- #*************************************************************************
- # FileName :alert_log_archive.sh
- #*************************************************************************
- # Author :Kerry
- # CreateDate :2013-07-02
- # blogs :www.cnblogs.com/kerrycode
- # Description :this script is made the alert log archived every day
- #*************************************************************************
- #! /bin/bash
- # these solved the oracle variable problem.
- export ORACLE_SID=gps
- export ORACLE_BASE=/u01/app/oracle
- date=`date +%Y%m%d`
- alert_log_path="$ORACLE_BASE/admin/$ORACLE_SID/bdump"
- alert_log_file="alert_$ORACLE_SID.log"
- alert_arc_file="alert_$ORACLE_SID.log""."${date}
- cd ${alert_log_path};
- if [ ! -e "${alert_log_file}" ]; then
- echo "the alert log didn't exits, please check file path is correct!";
- exit;
- fi
- if [ -e ${alert_arc_file} ];then
- echo "the alert log file have been archived!"
- else
- cat ${alert_log_file} >> ${alert_arc_file}
- cat /dev/null > ${alert_log_file}
- fi
- #*************************************************************************
- # FileName :alert_log_archive.sh
- #*************************************************************************
- # Author :Kerry
- # CreateDate :2013-07-0
- # blogs :www.cnblogs.com/kerrycode
- # Description :this script is made the alert log archived every day
- #*************************************************************************
- #! /bin/bash
- # these solved the oracle variable problem.
- export ORACLE_SID=gps
- export ORACLE_BASE=/u01/app/oracle
- date=`date +%Y%m%d`
- alert_log_path="$ORACLE_BASE/admin/$ORACLE_SID/bdump"
- alert_log_file="alert_$ORACLE_SID.log"
- alert_arc_file="alert_$ORACLE_SID.log""."${date}
- cd ${alert_log_path};
- if [ ! -e "${alert_log_file}" ]; then
- echo "the alert log didn't exits, please check file path is correct!";
- exit;
- fi
- if [ -e ${alert_arc_file} ];then
- echo "the alert log file have been archived!"
- else
- mv ${alert_log_file} ${alert_arc_file}
- cat /dev/null > ${alert_log_file}
- fi
监控告警日志文件
接下来看看如何监控告警日志文件的ORA错误,这里是采用Perl结合Shell的方式,因为Shell获取错误的时间、行数等不如Perl操作字符串方便。
- #**********************************************************************************
- # FileName :monitoring_alert_log.pl
- #**********************************************************************************
- # Author :Kerry
- # CreateDate :2013-07-01
- # blogs :www.cnblogs.com/kerrycode
- # Description :check the alert log and find out the ora error
- #**********************************************************************************
- # Modified Date Modified User Version Modified Reason
- # 2013-07-02 Kerry V01.0.1 add comment for this script
- #***********************************************************************************
- #! /usr/bin/perl
- use strict;
- my($argv) = @ARGV;
- if ( @ARGV != 1)
- {
- print '
- Parameter error: you must assined the alert log file as a input parameter or the number of prarameter is not right.
- ';
- exit
- }
- if( ! -e $argv )
- {
- print '
- Usage: monitoring_alert_log.pl
- $ cat alert_[sid].log | monitoring_alert_log.pl
- $ tail -f alert_[sid].log | monitoring_alert_log.pl
- $ monitoring_alert_log.pl alert_[sid].log
- ';
- exit;
- }
- my $err_regex = '^(\w+ \w+ \d{2} \d{2}:\d{2}:\d{2} \d{4})|(ORA-\d+:.+)$';
- my $date = "";
- my $line_counter = 0;
- while ( <> )
- {
- $line_counter++;
- if( m/$err_regex/oi )
- {
- if ($1)
- {
- $date = $1;
- next;
- }
- print "$line_counter | $date | $2 \n" if ($2);
- }
- }
- #**********************************************************************************
- # FileName : monitoring_alert_log.sh
- #**********************************************************************************
- # Author : Kerry
- # CreateDate : 2013-07-01
- # blogs : www.cnblogs.com/kerrycode
- # Description: check the alert log and find out the ora error
- #**********************************************************************************
- # Modified Date Modified User Version Modified Reason
- # 2013-07-02 Kerry V01.0.1 add comment and modified script
- #***********************************************************************************
- #!/bin/bash
- # these solved the oracle variable problem.
- export ORACLE_SID=gsp
- export ORACLE_BASE=/u01/app/oracle
- logfile="/home/oracle/scripts/alter_err_log.txt"
- pl_monitoring_alert="/home/oracle/scripts/monitoring_alert_log.pl"
- pl_sendmail="/home/oracle/scripts/sendmail.pl"
- alert_logfile="$ORACLE_BASE/admin/$ORACLE_SID/bdump/alert_$ORACLE_SID.log"
- #delete the old alter error log file
- rm -f${logfile}
- rm -f${pl_sendmail}
- #run the perl and check if exists the ora error
- perl ${pl_monitoring_alert} ${alert_logfile}> ${logfile}
- #if have no error in alert log then exit the program
- if [[ -e "${logfile}" && ! -s "${logfile}" ]]; then
- exit;
- fi
- date_today=`date +%Y_%m_%d`
- subject="Monitoring the Oracle Alert logs and find ora errors"
- content="Dear All,
- The Instance ${ORACLE_SID}\' alert log occured the ora errors ,please see the detail in attachment and take action for it. many thanks!
- Oracle Alert Services
- "
- echo "#!/usr/bin/perl" >> ${pl_sendmail}
- echo "use Mail::Sender;" >> ${pl_sendmail}
- echo "\$sender = new Mail::Sender {smtp => '10.xxx.xxx.xxx', from => 'xxxx@xxxx.com'}; ">> ${pl_sendmail}
- echo "\$sender->MailFile({to => 'kerry@xxxxx.com',">> ${pl_sendmail}
- echo "cc=>'konglb@esquel.com'," >> ${pl_sendmail}
- echo "subject => '$subject',">> ${pl_sendmail}
- echo "msg => '$content',">> ${pl_sendmail}
- echo "file => '$logfile'});">> ${pl_sendmail}
- perl ${pl_sendmail}
*/20 6-21 * * * /home/oracle/scripts/monitoring_alert_log.sh >/dev/null 2>&1
问题/优化脚本:Crontab 定时任务配置每二十分钟执行一次,结果,又有麻烦事情来了,假如8点发生了ORA错误,之后到下午6点都没有发生ORA错误,上面的脚本会每隔二十分钟发送一次邮件,重复发送,感觉比较烦人,而我需要的是:只有当新的ORA错误出现,才给DBA发送邮件,否则就不要发送,其次,感觉二十分钟的时间段太长了,如果出现了严重错误,二十分钟后才去处理,就显得时延比较滞后,但是如果你频率短的话, 基于第一个bug,你回收到N多邮件,那么我们继续改写,优化下面脚本吧
- #****************************************************************************************************
- # FileName :monitoring_alert_log.sh
- #****************************************************************************************************
- # Author :Kerry
- # CreateDate :2013-07-01
- # Description :check the alert log and find out the ora error
- #****************************************************************************************************
- # Modified Date Modified User Version Modified Reason
- # 2013-07-02 Kerry V01.0.1 add comment and modified script
- # 2013-07-02 Kerry V01.0.2 Solved the email repated send problems, only
- # the new ora error occured then send the email.
- #****************************************************************************************************
- #!/bin/bash
- # these solved the oracle variable problem.
- export ORACLE_SID=gsp
- export ORACLE_BASE=/u01/app/oracle
- new_log_file="/home/oracle/scripts/new_err_log.txt"
- old_log_file="/home/oracle/scripts/old_err_log.txt"
- pl_monitoring_alert="/home/oracle/scripts/monitoring_alert_log.pl"
- pl_sendmail="/home/oracle/scripts/sendmail.pl"
- alert_logfile="$ORACLE_BASE/admin/$ORACLE_SID/bdump/alert_${ORACLE_SID}.log"
- #delete the old alter error log file
- #rm -f${new_log_file}
- rm -f${old_log_file}
- mv ${new_log_file}${old_log_file}
- rm -f${pl_sendmail}
- #run the perl and check if exists the ora error
- perl ${pl_monitoring_alert} ${alert_logfile}> ${new_log_file}
- #if have no error in alert log then exit the program
- if [[ -e "${new_log_file}" && ! -s "${new_log_file}" ]]; then
- exit;
- fi
- new_err_num=`cat ${new_log_file} | wc -l`
- old_err_num=`cat ${old_log_file} | wc -l`
- if [ ${new_err_num} -le ${old_err_num} ]; then
- exit
- fi
- date_today=`date +%Y_%m_%d`
- subject="xxx (192.168.xxx.xxx) Monitoring the Oracle Alert logs and find ora errors"
- content="Dear All,
- The Instance ${ORACLE_SID}\' alert log occured the ora errors ,please see the detail in attachment and take action for it. many thanks!
- Oracle Alert Services
- "
- echo "#!/usr/bin/perl" >> ${pl_sendmail}
- echo "use Mail::Sender;" >> ${pl_sendmail}
- echo "\$sender = new Mail::Sender {smtp => '10.xxx.xxx.xxx', from => 'xxxx@xxxx.com'}; ">> ${pl_sendmail}
- echo "\$sender->MailFile({to => 'kerry@xxxxxx.com',">> ${pl_sendmail}
- echo "cc=>'xxxxx@xxxxx.com'," >> ${pl_sendmail}
- echo "subject => '$subject',">> ${pl_sendmail}
- echo "msg => '$content',">> ${pl_sendmail}
- echo "file => '${new_log_file}'});">> ${pl_sendmail}
- perl ${pl_sendmail}
但是我在部署过程中,由于环境问题(多台ORACLE服务器,不同的操作系统、不同的环境),发送邮件的部分出现改动,又有下面两个小版本的改动
- #**********************************************************************************
- # FileName : monitoring_alert_log.sh
- #**********************************************************************************
- # Author : Kerry
- # CreateDate : 2013-07-01
- # Description: check the alert log and find out the ora error
- #***********************************************************************************
- # Modified Date Modified User Version Modified Reason
- # 2013-07-02 Kerry V01.0.1 add comment and modified script
- # 2013-07-02 Kerry V01.0.2 Solved the email repated send problems, only
- # the new ora error occured then send the email
- #***********************************************************************************
- #!/bin/bash
- new_log_file="/home/oracle/scripts/new_err_log.txt"
- old_log_file="/home/oracle/scripts/old_err_log.txt"
- pl_monitoring_alert="/home/oracle/scripts/monitoring_alert_log.pl"
- email_content="/home/oracle/scripts/sendmail.txt"
- alert_logfile="$ORACLE_BASE/admin/$ORACLE_SID/bdump/alert_$ORACLE_SID.log"
- #delete the old alter error log file
- rm -f${old_log_file}
- mv ${new_log_file} ${old_log_file}
- rm -f${pl_sendmail}
- #run the perl and check if exists the ora error
- perl ${pl_monitoring_alert} ${alert_logfile}> ${new_log_file}
- #if have no error in alert log then exit the program
- if [[ -e "${new_log_file}" && ! -s "${new_log_file}" ]]; then
- exit;
- fi
- new_err_num=`cat ${new_log_file} | wc -l`
- old_err_num=`cat ${old_log_file} | wc -l`
- if [ ${new_err_num} -le ${old_err_num} ]; then
- exit
- fi
- date_today=`date +%Y_%m_%d`
- subject="Monitoring the Oracle Alert logs and find ora errors"
- content="Dear All,
- The Instance ${ORACLE_SID}\' alert log occured the ora errors ,please see the detail in attachment and take action for it. many thanks!
- The Error is blow :
- "
- echo 'Content-Type: text/html' > ${email_content}
- echo 'To: xxxxx@xxxxx.com' >> ${email_content}
- echo ${subject} >> ${email_content}
- echo '<pre style="font-family: courier; font-size: 9pt">' >> ${email_content}
- echo ${content} >> ${email_content}
- cat ${new_log_file} >>${email_content} 2>&1
- echo 'Oracle Alert Services' >> ${email_content}
- /usr/sbin/sendmail -t -f ${subject} < ${email_content}
- rm -f ${email_content}
- #**********************************************************************************
- # FileName : monitoring_alert_log.sh
- #**********************************************************************************
- # Author : Kerry
- # CreateDate :2013-07-01
- # Description: check the alert log and find out the ora error
- #***********************************************************************************
- # Modified Date Modified User Version Modified Reason
- # 2013-07-02 Kerry V01.0.1 add comment and modified script
- # 2013-07-02 Kerry V01.0.2 Solved the email repated send problems, only
- # the new ora error occured then send the email
- #***********************************************************************************
- #!/bin/bash
- new_log_file="/home/oracle/scripts/new_err_log.txt"
- old_log_file="/home/oracle/scripts/old_err_log.txt"
- pl_monitoring_alert="/home/oracle/scripts/monitoring_alert_log.pl"
- email_content="/home/oracle/scripts/sendmail.pl"
- alert_logfile="$ORACLE_BASE/admin/$ORACLE_SID/bdump/alert_$ORACLE_SID.log"
- reportname="alert_log_err.txt"
- #delete the old alter error log file
- rm -f${old_log_file}
- mv ${new_log_file} ${old_log_file}
- rm -f${pl_sendmail}
- #run the perl and check if exists the ora error
- perl ${pl_monitoring_alert} ${alert_logfile}> ${new_log_file}
- #if have no error in alert log then exit the program
- if [[ -e "${new_log_file}" && ! -s "${new_log_file}" ]]; then
- exit;
- fi
- date_today=`date +%Y_%m_%d`
- subject="Monitoring the Oracle Alert logs and find ora errors"
- content="Dear All,
- The Instance ${ORACLE_SID}\' alert log occured the ora errors ,please see the detail in attachment and take action for it. many thanks!
- Oracle Alert Services
- "
- ( ${content} ; uuencode ${new_log_file} ${reportname} ) | /bin/mail -s ${subject} xxxx@xxxx.com xxxxx@xxx.com
- /bin/mail
转载于:https://www.cnblogs.com/kerrycode/p/3168662.html
归档—监控ORACLE数据库告警日志相关推荐
- Oracle的告警日志之v$diag_alert_ext视图
Oracle的告警日志之v$diag_alert_ext视图 Oracle的告警日志之v$diag_alert_ext视图 最近由于自己写的一个job老是报错,找不出来原因,数据库linux的term ...
- 监控Oracle数据库
介绍了DBA每天在监控Oracle数据库方面的职责,讲述了如何通过shell脚本来完成这些重复的监控工作.本文首先回顾了一些DBA常用的Unix命令,以及解释了如何通过Unix Cron来定时执行DB ...
- 监控Oracle数据库的常用shell脚本
文章介绍了DBA每天在监控Oracle数据库方面的职责,讲述了如何通过shell脚本来完成这些重复的监控工作.本文首先回顾了一些DBA常用的Unix命令,以及解释了如何通过Unix Cron来定时执行 ...
- 监控Oracle数据库的常用shell脚本 ORACLE教程 教程作者:佚名 教程来源:不详 教程栏目:ORACLE教程
前言 这篇文章介绍了DBA每天在监控Oracle数据库方面的职责,讲述了如何通过shell脚本来完成这些重复的监控工作.本文首先回顾了一些DBA常用的Unix命令,以及解释了如何通过Unix Cron ...
- zabbix如何监控oracle,使用zabbix监控oracle数据库的方法详解
一.概述 zabbix是一款非常强大,同时也是应用最为广泛的开源监控软件,本文将给大家介绍如何利用zabbix+python监控oracle数据库. 二.环境介绍 以下是我安装的环境,实际部署时并不需 ...
- 记一次ORACLE数据库redo日志文件损坏故障恢复
记一次ORACLE数据库redo日志文件损坏故障恢复 环境 ORACLE 11G R2 + RAC+ ASM 归档模式 问题描述 数据库1节点状态变为Stuck Archiver,alert日志报Ar ...
- 监控oracle数据io,Prometheus监控Oracle数据库
背景 本文简单介绍下,Prometheus如何通过exporters监控Oracle数据库,以及应该注意哪些指标. oracledb_exporter oracledb_exporter是一个连接到O ...
- lepus监控oracle数据库_lepus天兔数据库监控系统搭建记录
一.开场白 去年的锅,今年才接.时间都耗在了各种业务测试上,上周刚刚把锅甩了,赶紧把以前没完成的事做完. 二.lepus简介 简洁.直观.强大的开源数据库监控系统,MySQL/Oracle/Mongo ...
- lepus监控oracle数据库_MySQL数据库监控软件lepus使用问题以及解决办法
在使用lepus3.7监控MySQL数据库的时候,碰到了以下几个问题,本博客给出了这些问题产生的原因,以及相应的解决办法. 1. 问题1:php页面无法连接数据库 直接使用php程序执行php文件,可 ...
最新文章
- 12.1 LNMP架构介绍;12.2 MySQL安装;12.3-2.4 PHP安装(上下);12.5
- 从C ++定义QML类型
- 堆排序原理及其实现(C++)
- c#读取solidworks文件_C#初学者教程系列20:Stream流读写
- 20131222-Dom省市加载-第二十七天
- react中对于key值的理解
- PHP CURL实现远程下载文件到本地
- M1 Mac上运行Windows 11
- 如何去掉桌面图标上的小箭头
- 算法:Unix是如何简化路径的Simplify Path简化路径规则
- c语言实训项目,C语言项目实训教程
- Python多线程好玩弹窗代码
- svn代码量统计工具StatSVN的使用
- zigbee学习之JN5169 串口UARTs
- Python——批量发送邮件(持续更新)
- arcgis导出的图片无效_img影像在arcgis中生成JPG图片空白求解
- RT-Thread实战笔记|LD3320非限定词条语音控制器使用详解
- Web GIS 航拍实现的智慧园区数字孪生应用
- 3344avd_AVD生根
- Linux Ethernet PHY 驱动
热门文章
- python制作动图-用Python制作迷宫GIF
- python语言入门z-python中a z
- python资源百度网盘-bypy-百度网盘Python客户端 linux
- 学python就业要看哪些书-人人学Python,为什么就业拿高薪的那么少?
- python自学步骤-小白刚入门Python,学完基础后,接下来的学习步骤!
- python创建csv文件并写入-Python 读写 CSV
- 怎么自学python编程-怎么自学python?
- python怎么安装requests库-小白安装python的第三方库:requests库
- python入门编程题库-Python经典基础编程练习题(六)——每日10题
- python基础实例-Python 练习实例14