解析日志时,Logstash报告[0] _grokparsefailure

问题描述 投票:9回答:1

我有来自这种格式的日志。我已将logstash变量分配给下面的模式。我相信我已经使用随附的预定义Grok标记正确分配了这些元素。但是,当我运行logstash时,它反映:[0]“_ grokparsefailure”表示它无法解析请求。对于我的conf确实出错了,我感到很茫然。这里有没有人知道是什么原因造成的?我对logstash很新。提前致谢

1383834858 0 71.172.136.12 20097903 198.2.20.171 80 TCP_HIT / 200 252 HEAD http://podcasts.someserver.com/80830A/podcasts.someserver.com/nyv/voice-film-club/2013/11/the-sexy-god-thor.mp3 - 0 355“ - ”“Podcasts / 2.0”33546“ - ”

要么

%{BASE10NUM:timestamp} = 1383834858
%{BASE10NUM:time_taken} = 0
%{IP:clientip} = 71.172.136.12
%{BASE10NUM:filesize} = 20097903
%{IP:serverip} = 198.2.20.171
%{BASE10NUM:port} = 80
%{WORD:status_code} = TCP_HIT/200
%{BASE10NUM:sc_bytes} = 252
%{WORD:method} = HEAD
%{URI:cs_uri} = http://podcasts.someserver.com/80830A/podcasts.someserver.com/nyv/voice-   film-club/2013/11/the-sexy-god-thor.mp3
%{NOTSPACE:ignore2} = -
%{BASE10NUM:rs_duration} = 0
%{BASE10NUM:rs_bytes} = 355
%{QS:c_referrer} = "-"
%{QS:user_agent} = "Podcasts/2.0"
%{BASE10NUM:customerid} = 33546
%{QS:ignore} = "-"

我的logstash.conf文件如下所示:

input {
    #wpa_media logs from the CDN(see puppet module)
    redis {
        type => "wpc_media"
        host => "devredis1.somedomain.com"
        # these settings should match the output of the agent
        data_type => "list"
        key => "wpc_media"
        codec => json
        debug => true
   }
}


filter {
    grok {
        type    => "wpc_media"
        pattern => [ "%{BASE10NUM:timestamp} %{BASE10NUM:time_taken} %{IP:clientip} %{BASE10NUM:filesize} %{IP:serverip} %{BASE10NUM:port} %{WORD:status_code} %{BASE10NUM:sc_bytes} %{WORD:method} %{URI:cs_uri} %{NOTSPACE:ignore2} %{BASE10NUM:rs_duration} %{BASE10NUM:rs_bytes} %{QS:c_referrer} %{QS:user_agent} %{BASE10NUM:customerid} %{QS:ignore} " ]
    }

    mutate {
        #just something to cover up the error not really fixing it
        #remove_tag  => [ "_grokparsefailure" ]
        remove => [ "customer_id", "ignore", "c_referrer", "time_taken" ]
    }
}
output {
    stdout { debug => true debug_format => "ruby"}
}
elasticsearch redis logstash kibana logstash-grok
1个回答
27
投票

为了您自己的参考,GrokDebugger网站对于这样的问题非常方便。

对于您提供的特定日志事件,%{WORD}TCP_HIT/200不匹配。

一个快速解决方法是与%{DATA:status_code}匹配(你可以看到built-in patterns on GitHub)。你当然可以建立一个更有针对性的匹配,但是如果没有看到可能的输入就很难做到。

如果你总是期待word/number,像(?<status_code>%{WORD}/%{INT})这样的东西可以工作。

© www.soinside.com 2019 - 2024. All rights reserved.