监控oracle 的alert.log-凯发app官方网站

凯发app官方网站-凯发k8官网下载客户端中心 | | 凯发app官方网站-凯发k8官网下载客户端中心
  • 博客访问: 3502775
  • 博文数量: 718
  • 博客积分: 1860
  • 博客等级: 上尉
  • 技术积分: 7790
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-07 08:51
个人简介

偶尔有空上来看看

文章分类

全部博文(718)

文章存档

2024年(4)

2023年(74)

2022年(134)

2021年(238)

2020年(115)

2019年(11)

2018年(9)

2017年(9)

2016年(17)

2015年(7)

2014年(4)

2013年(1)

2012年(11)

2011年(27)

2010年(35)

2009年(11)

2008年(11)

最近访客
相关博文
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·

分类: oracle

2011-06-30 14:54:02

流程:
定时将alert 部分内容取出来,通过外部表访问,然后以一个过程来分析外部表中内容,将严重警告信息插入到一个警告表中。
 
 


以oracle用户登录后

mkdir $home/check_agent


crontab 中
0 8 * * * $home/check_agent/cut_alert.sh


touch cut_alert.sh
chmod ux cut_alert.sh
vi cut_alert.sh

# 获取最近的报警日志

export alertlog=/oracle/admin/orcl/bdump/alert_orcl.log

tail -2000 $alertlog > $home/check_agent/alert_temp.$$


sqlplus /nolog
conn /as sysdba
grant connect,resource to brjljk;
conn brjljk/brjljk

define alert_length="2000"

drop table alert_log;

create table alert_log (
  alert_date date,
  alert_text varchar2(&&alert_length)
)
storage (initial 512k next 512k pctincrease 0);

create index alert_log_idx on alert_log(alert_date)
storage (initial 512k next 512k pctincrease 0);

column db new_value _db noprint;
column bdump new_value _bdump noprint;

select instance_name db from v$instance;

select value bdump from v$parameter
 where name ='background_dump_dest';


drop directory bdump;
create directory bdump as '&&_bdump';

drop table alert_log_disk;

create table alert_log_disk ( text varchar2(&&alert_length) )
organization external (
  type oracle_loader
  default directory bdump
      access parameters (
          records delimited by newline nologfile nobadfile
          fields terminated by "&" ltrim
      )
  location('alert_&&_db..log')
)
reject limit unlimited;



create or replace procedure update_alert_log as
begin
  declare

    isdate number := 0;
    start_updating number := 0;
    rows_inserted number := 0;

    alert_date date;
    max_date date;

    alert_text alert_log_disk.text%type;

  begin

    /* find a starting date */
    select max(alert_date) into max_date from alert_log;

    if (max_date is null) then
      max_date := to_date('01-05-2011', 'dd-mm-yyyy');
    end if;

    for r in (select substr(text, 1, 180) text
                from alert_log_disk r
               where (text like 'ora-%' --添加自己的过滤信息

                 or text like 'warning%')
                 or substr(r.text, 21) in ('2011',
                                    '2012',
                                    '2013',
                                    '2014'
                                    '2015',
                                    '2016'
                                    '2017',
                                    '2018',
                                    '2019',
                                    '2020')
              ) loop

      isdate := 0;
      alert_text := null;

      select count(*)
        into isdate
        from dual
       where substr(r.text, 21) in ('2011',
                                    '2012',
                                    '2013',
                                    '2014'
                                    '2015',
                                    '2016'
                                    '2017',
                                    '2018',
                                    '2019',
                                    '2020')
         and r.text not like '%cycle_run_year%'; --这里做过修改,添加了当前年份


      if (isdate = 1) then
        -- dbms_output.put_line(substr(r.text, 5));

        select to_date(substr(r.text, 5),
                       'mon dd hh24:mi:ss rrrr',
                       'nls_date_language = american') --这里做了修改,alert文件日期格式为英文格式

          into alert_date
          from dual;

        if (alert_date > max_date) then
          start_updating := 1;
        end if;

      else
        alert_text := r.text;
      end if;

      if (alert_text is not null) and (start_updating = 1) then

        insert into alert_log
        values
          (alert_date, substr(alert_text, 1, 180));
        rows_inserted := rows_inserted 1;
        commit;

      end if;

    end loop;

    sys.dbms_output.put_line('inserting after date ' || to_char(max_date, 'mm/dd/rrhh24:mi:ss'));
    sys.dbms_output.put_line('rows inserted: ' || rows_inserted);

    commit;

  end;
end;


--

job 来定时刷新当前的alert 并清除旧的


阅读(4633) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~
")); function link(t){ var href= $(t).attr('href'); href ="?url=" encodeuricomponent(location.href); $(t).attr('href',href); //setcookie("returnouturl", location.href, 60, "/"); }
网站地图