oracle 服务端日志,check_logfile监控oracle的日志以及其他各种日志

nagios的插件见:

日志文件监控的重要性就不用多说了,定期查看操作系统、数据库或应用的日志文件,检查时候有错误或异常,是系统管理员的规定动作。

check_logfiles——Consol Labs出品,功能一如既往的强大,网站提供了很多典型应用案例,此外用户只要掌握一定的正则表达式知识,完全可以根据自己的具体应用进行定制。

一:介绍:

check_logfiles解释一个配置文件,你可以自定义设置如下的选项

1.

$seekfilesdir 写状态信息文件的目录。状态信息文件帮助check_logfiles记住过去已经检查过的日志内容

2.

$protocolsdir 写协议信息文件的目录。协议信息文件包含了日志检查时匹配的内容

3.

$scriptpath 冒号分隔的目录,这些目录存放着可执行程序或脚本供 check_logfiles 调用。

4.

$MACROS 定义宏,然后你可以在表达式中使用这些宏,调用形式$MACROS$。宏的定义形式如:$MACROS = { CL_DOMAIN

=> ‘muc’, CL_VG00 => ‘/dev/vg00’

}。如果你没有定义宏,可仍然可以使用预定义宏:

$CL_HOSTNAME$ 不带域的主机名

$CL_IPADDRESS$ IP地址

$CL_DATE_YYYY$ 年份(1970…)

$CL_DATE_MM$ 月份(01..12)

$CL_DATE_DD$ 日(01..31)

$CL_DATE_HH$ 小时(00..23)

$CL_DATE_MI$ 分钟(00..59)

$CL_DATE_SS$ 秒(00..59)

$CL_SERVICEDESC$ 来源于配置文件中的服务描述

$CL_NSCA_SERVICEDESC$ dto

$CL_NSCA_HOST_ADDRESS$ 本机地址127.0.0.1

$CL_NSCA_PORT$ 5667

$CL_NSCA_TO_SEC$ 10

$CL_NSCA_CONFIG_FILE$ send_nsca.cfg

还有一些宏的值,在check_logfile运行时,是变的:

$CL_LOGFILE$ 当前日志的名字

$CL_TAG$ 当前的tag

$CL_SERVICESTATEID$ 最后匹配的状态(0..3)

$CL_SERVICEOUTPUT$ 最后匹配的文本

5. @searches 一个列表,列表里存放着哈希表的索引。哈希表中描述了到哪里去寻找,匹配些什么,匹配到了怎么做等内容。向前兼容@logs

a) tag 如果在@logs里包含了多个条目处理同一个日志文件。那么由于seekfile根据日志文件名来生成的,则上述情况将会造成问题。tag将被用于seekfile的名字中。

b) logfile

日志文件的名字,一般的如/var/adm/messages,/var/log/syslog.log。如果日志名字由日期组成,如LOGBUCH20060801230000,可以在日志名字中使用宏来匹配(

logfile =>

’LOGBUCH$CL_DATE_YYYY$$CL_DATE_MM$$CL_DATE_DD$...’

) c) archivedir

系统写rotated日志文件的目录,一般和日志文件目录相同。

d) rotation

用来匹配归档的日志文件。假设你的日志目录下现在存在messages messages.0 messages.1.gz

suelzomat.log suelzomat.old.1 suelzomat.old.2 suelzomat.old.3

suelzomat.old.4 suelzomat.old.5 suelzomat.old.6 suelzomat.old.7

uucp.log

那么你可以这样匹配rotate日志( rotate => ’suelzomat.old.[0-9]’

)

e) criticalpatterns

一个正则表达式或者一组正则表达式,用来匹配日志文件中的严重错误。

criticalpatterns => [’.*Sense Key: Media

Error.*’,’.*Sense Key: Not Ready.*’,’.*Sense Key: Hardware

Error.*’, ...]

你可以在表达式前加上“!”,这样搜索的意义就反转了,即:如果没有匹配就报警。

f) criticalexceptions

用于排除criticalpatterns匹配中的某些部分。如

criticalpatterns => '.*Failed password for illegal

user.*',

criticalexceptions => '.*Failed password for illegal

user lausser'

g) criticalthreshold

这个数值设置了忽略匹配的次数。如设置成5,即忽略前4次匹配,第五次匹配才计数。

h) warningpatterns

i) warningexceptions

j) warningthreshold

k) options

一个逗号分隔的选项列表,可能的值如下:

- [no]protocol

如果匹配日志成功,则将匹配的行写道protocol文件中,protocol文件名来源于配置文件名和时间的组合。例如在12:00执行了check_logfiles

–f

check_oracle_alerts。配置文件名为check_oracle_alerts.cfg。则相应的匹配行将写入$protocoldir/check_oracle_alerts.protocol-2006-03-14-12-00-02

默认值是protocol。

- [no]count

如果一个表达式匹配,无论是错误还是警告,技术器都增加。最终达到某值将导致插件退出。

默认值是count

- [no]syslogserver

如果这个系统是日志服务器,那么设置了这个选项,将匹配.*(your_servers_hostname|localhost).*

这里的主机名是不带域的。

如果有相同主机名但不同域名的主机也将日志存在这台机器上,你可以设置nosyslogserver,然后使用模式.*($CL_HOSTNAMEFQDN$|localhost).*

来匹配。

l) script

如果你设置了script选项,则一个script或者binary将被调用。这个可执行程序必须存放在$scriptpath。默认的,script是不输出任何东西的,相关的信息将传给环境变量:

CHECK_LOGFILES_LOGFILE 模式在哪个日志文件中被匹配

CHECK_LOGFILES_SERVICESTATE @searches里的tag

CHECK_LOGFILES_SERVICESSTATE WARNING或者CRITICAL

CHECK_LOGFILES_SERVICESTATID 1或者2

CHECK_LOGFILES_SERVICEOUTPUT 匹配的行

CHECK_LOGFILES_HSOTNAME 本机的名字

m) scriptparams

可执行程序的参数。如 scriptparams => ‘-H

$CL_NSCA_HOST_ADDRESS$’;

n) scriptstdin

如果你想往可执行程序的输入上写东西,可以使用这个选项。例如输入一个字符串: scriptstdin

=> ‘$CL_HOSTNAME$\t$CL_SERVICEDESC$\t$CL_SERVICESTATEID$\n’;

o) scriptdelay

可执行程序执行完成后,spleep的时间,然后check_logfiles才继续运行。

6. $protocolretention

你想保存protocol文件的天数。默认为7天。

7. prescript

在check_logfiles运行前执行的程序。CHECK_LOGFILES_TAG将被设置为”startup”,服务状态总是OK。prescriptparams/prescriptstdin/prescriptdelay

8. postscript

CHECK_LOGFILES_TAG将被设置为”summary”。 postscriptparams/postscriptstdin/postdelay

#############################################

二:安装

./configure --prefix=/usr/local/nagios/

--with-nagios-user=nagios --with-nagios-group=nagios

--with-seekfiles-dir=/usr/local/nagios/var/tmp/

--with-protocols-dir=/usr/local/nagios/var/tmp/

--with-perl=/usr/bin/perl --with-gzip=/bin/gzip &&make && make install

三:检查测试

在libexec下有check_logfiles

[root@10.10.10.140 ~]$ ll

/usr/local/nagios/libexec/check_logfiles -rwxr-xr-x 1 root root 185174 2011-12-19

15:58:26.000000000 +0800

/usr/local/nagios/libexec/check_logfiles

[root@10.10.10.140 ~]$ /usr/local/nagios/libexec/check_logfiles --tag=error

--logfile=/var/log/messages OK -

no errors or warnings|error_lines=0 error_warnings=0

error_criticals=0 error_unknowns=0

四:应用

1、监控oracle的日志

oracle的日志在“/opt/app/oracle/admin/orcl/bdump/alert_orcl.log”

1.1: 创建db_alertlog.cfg方便check_logfiles调用

cat db_alertlog.cfg

@searches = ({

tag => 'oraalerts',

logfile =>

'/opt/app/oracle/admin/orcl/bdump/alert_orcl.log',

criticalpatterns => [

'ORA\-0*204[^\d]', # error in reading control file

'ORA\-0*206[^\d]', # error in writing control file

'ORA\-0*210[^\d]', # cannot open control file

'ORA\-0*257[^\d]', # archiver is stuck

'ORA\-0*333[^\d]', # redo log read error

'ORA\-0*345[^\d]', # redo log write error

'ORA\-0*4[4-7][0-9][^\d]',# ORA-0440 - ORA-0485 background process

failure

'ORA\-0*48[0-5][^\d]',

'ORA\-0*6[0-3][0-9][^\d]',# ORA-6000 - ORA-0639 internal

errors

'ORA\-0*1114[^\d]', # datafile I/O write error

'ORA\-0*1115[^\d]', # datafile I/O read error

'ORA\-0*1116[^\d]', # cannot open datafile

'ORA\-0*1118[^\d]', # cannot add a data file

'ORA\-0*1122[^\d]', # database file 16 failed verification check

'ORA\-0*1171[^\d]', # datafile 16 going offline due to error advancing checkpoint

'ORA\-0*1201[^\d]', # file 16 header failed to write correctly

'ORA\-0*1208[^\d]', # data file is an old version - not accessing current version

'ORA\-0*1578[^\d]', # data block corruption

'ORA\-0*1135[^\d]', # file accessed for query is offline

'ORA\-0*1547[^\d]', # tablespace is full

'ORA\-0*1555[^\d]', # snapshot too old

'ORA\-0*1562[^\d]', # failed to extend rollback segment

'ORA\-0*162[89][^\d]', # ORA-1628 - ORA-1632 maximum extents exceeded

'ORA\-0*163[0-2][^\d]',

'ORA\-0*165[0-6][^\d]', # ORA-1650 - ORA-1656 tablespace is full

'ORA\-16014[^\d]', # log cannot be archived, no available destinations

'ORA\-16038[^\d]', # log cannot be archived

'ORA\-19502[^\d]', # write error on datafile

'ORA\-27063[^\d]', # number of bytes read/written is incorrect

'ORA\-27037[^\d]', # unable to obtain file status

'ORA\-0*4031[^\d]', # out of shared memory.

'No space left on device',

'Archival Error',

],

warningpatterns => [

'ORA\-0*3113[^\d]', # end of file on communication channel

'ORA\-3136[^\d]', # inbound connection timed ou

'ORA\-0*6501[^\d]', # PL/SQL internal error

'ORA\-0*1140[^\d]',

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值