全部博文(403)
分类: 系统运维
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 本文出自 51CTO.COM技术博客 |