免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1618 | 回复: 0
打印 上一主题 下一主题

nagios插件-监控你的oracle alert日志 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-09-01 10:38 |只看该作者 |倒序浏览

版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章
原始出处
、作者信息和本声明。否则将追究法律责任。
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
本文出自 51CTO.COM技术博客


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/15315/showart_2042783.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP