我在Logstash日志中收到以下内容,但无法弄清楚它来自何处:
{:timestamp =>“2016-05-19T12:14:00.883000-0400”,:message =>“发生了Ruby异常:nil的未定义方法`[]':NilClass”,:level => :错误}
我也有其他一些错误,我无法判断哪条记录是由它引起的。我怀疑我的错误来自日期操作,但问题更为笼统。
如何让logstash打印导致此错误的整个事件或任何类似错误?
我的过滤器输出如下所示,输入来自JDBC源:
filter {
mutate
{
convert => [ "dt", "string" ]
}
date {
match => [ "dt", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"]
}
ruby {
code => "event['idx'] = event['dt'][0..9]"
}
ruby {
code => "event['id'] = event['@timestamp'].time().to_f.to_s + '' + event['sessionid']"
}
}
output {
stdout {
codec => rubydebug
}
elasticsearch {
hosts => ["localhost" ]
index => "prefix-%{idx}"
document_id => "%{id}"
}
}
答案 0 :(得分:1)
此行似乎是filter
过滤器的ruby
方法:
def filter(event)
begin
@codeblock.call(event)
filter_matched(event)
rescue Exception => e
@logger.error("Ruby exception occurred: #{e}")
event.tag("_rubyexception")
end
end
我认为您可以添加错误消息来打印event
。因此,您将知道哪个事件导致错误:
def filter(event)
begin
@codeblock.call(event)
filter_matched(event)
rescue Exception => e
@logger.error("Ruby exception occurred: #{e}")
@logger.error("Event causing error: #{event}") # <= Log event
event.tag("_rubyexception")
end
end
它位于文件:vendor / bundle / jruby / 1.9 / gems / logstash-filter-ruby-2.0.5 / lib / logstash / filters / ruby.rb for Logstash 2.3.2