要点:
logstash - > elasticsearch - >解析调试输出中显示的日期失败
日志文件中的事件包含字段@timestamp(格式:2014-06-18T11:52:45.370636 + 02:00)
事件实际上被处理为elasticsearch,但显示“失败的解析”错误。
版本:
Logstash 1.4.1
Elasticsearch 1.20
我做错了吗?
我有包含以下事件的日志文件:
{"@timestamp":"2014-06-18T11:52:45.370636+02:00","Level":"Info","Machine":"X100","Session":{"MainId":0,"SubId":"5otec"},"Request":{"Url":"http://www.localhost:5000/Default.aspx","Method":"GET","Referrer":"http://www.localhost:5000/Default.aspx"},"EndRequest":{"Duration":{"Main":0,"Page":6720}}}
我使用此logstash配置:
input {
file {
path => "D:/testlogs/*.log"
codec => "json"
start_position => [ "beginning" ]
}
}
filter {
date {
match => [ "@timestamp", "ISO8601" ]
}
}
output {
stdout {
codec => json
}
elasticsearch {
protocol => http
host => "10.125.26.128"
}
}
当我使用此配置对日志文件中的事件运行logstash时,我收到以下错误:
[33mFailed parsing date from field {:field=>"@timestamp", :value=>"2014-06-18T12:18:34.717+02:00", :exception=>#<TypeError: cannot convert instance of class org.jruby.RubyTime to class java.lang.String>
现在事实是,事件是在elasticsearch中导入的,但我看到了这些错误 这可能是一个问题,还是可以忽略这些失败的解析错误?
答案 0 :(得分:1)
您的日志已经是json格式,因此您无需解析日期。 您可以使用json过滤器来解析所有字段和值。
例如,使用此配置:
input {
file {
path => "D:/testlogs/*.log"
codec => "json"
}
}
filter {
json {
source => "message"
}
}
output {
stdout {
codec => rubydebug
}
}
我可以成功解析您的日志。输出是:
{
"@timestamp" => "2014-06-18T17:52:45.370+08:00",
"Level" => "Info",
"Machine" => "X100",
"Session" => {
"MainId" => 0,
"SubId" => "5otec"
},
"Request" => {
"Url" => "http://www.localhost:5000/Default.aspx",
"Method" => "GET",
"Referrer" => "http://www.localhost:5000/Default.aspx"
},
"EndRequest" => {
"Duration" => {
"Main" => 0,
"Page" => 6720
}
},
"@version" => "1",
"host" => "ABC",
"path" => "D:/testlogs/*.log"
}
我也试过文件输入中的codec => json
不起作用但是在stdin输入中工作。也许这是logstash中的一个错误。
希望这可以帮到你。