Chinaunix首页 | 论坛 | 博客
  • 博客访问: 408326
  • 博文数量: 403
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: -70
  • 用 户 组: 普通用户
  • 注册时间: 2016-09-05 12:45
文章分类

全部博文(403)

文章存档

2014年(3)

2013年(1)

2012年(3)

2011年(21)

2010年(13)

2009年(64)

2008年(9)

2007年(36)

2006年(253)

分类: 系统运维

2009-09-01 10:38:01

版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://aviar.blog.51cto.com/361632/124444
虽然oracle自带的监控也异常强大
 
不过我们使用用nagios的话,可以和短信报警结合起来,对监控的效果会有大幅度提高
 
下面就是针对oracle的日志写的脚本
 
处理最后“1000行 && 1小时内” 的日志
 
#!/usr/bin/perl -w

use strict;
use File::Tail;
use Data::Dumper;
use Date::Manip;

my $oracle_log = "/home/oracle/admin/orcl/bdump/alert_orcl.log";
my $limit            = 1000;

my $now = localtime;
$now = ParseDate($now);
$now =~ s/://g;

my $fh = File::Tail->new( name => $oracle_log, tail => $limit );
if ( !defined $fh ) {
        die "Could not create File::Tail object on $oracle_log: $!\n";
}
$fh->nowait(1);

my %errors;

#local $" = "";
my $count = 0;
my $start = 0;

while ( defined( my $line = $fh->read() ) ) {
        last unless $line;
        chomp($line);

        #print $count++ . ": " . $line . "\n";
        $count++;

        # Wed Jan 24 20:41:40 2007
        # ORA-00313: open failed for members of log group 1 of thread 1
        if ( $line =~ m{(\w+\s+\d+\s+\d{2}:\d{2}:\d{2}\s+\d{4})} ) {
                my $time = ParseDate($1);
                $time =~ s/://g;
                # 20080804111059
                if ( $time > ( $now - 10000 ) ) {
                                $start = 1;
                }
        }
        if ( ( $start == 1 ) && ( $line =~ m{(ORA-\d+)[:]?\s+(.+)} ) ) {
                #next if ( $line =~ m{ORA-00942} ); #skip some special errors
                #next if ( $line =~ m{ORA-07445} );
                $errors{$1} = $2;
        }
}

if ( scalar keys %errors ) {
                foreach my $tmp ( keys %errors ) {
                                print $tmp .": " . $errors{$tmp} . "\n";
                }
                exit 2;
} else {
                print "Oracle log is ok\n";
                exit 0;
}

本文出自 “木木的布劳格” 博客,请务必保留此出处http://aviar.blog.51cto.com/361632/124444

阅读(1370) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~