Grok配置ELK

时间:2017-06-27 14:02:16

标签: elasticsearch logstash kibana

我有一个原始类型的日志要解析。语法是:

2013-01-05 03:29:38,842 INFO  [ajp-bio-8009-exec-69] web.CustomAuthenticationSuccessHandler - doLogin : admin.ebusiness date : 2013-01-05 03:29:38

当我使用grok模式时:

if [type] in ["edai"] {
            grok {
            match => { "message" => ["%{YEAR:year}-%{WORD:month}-%{DATA:day} %{DATA:hour}:%{DATA:minute}:%{DATA:second},%{DATA:millis} %{NOTSPACE:loglevel} {0,1}%{GREEDYDATA:message}"] }
            overwrite => [ "message" ]
        }
    }

模式可以正常工作,但是当我进入Kibana时,日志会停留在"消息中的一个块中。这样的部分:

2013-01-05 23:27:47,030 INFO [ajp-bio-8009-exec-63] web.CustomAuthenticationSuccessHandler - doLogin : admin.ebusiness date : 2013-01-05 23:27:47

我更喜欢这样:

{ "year": [["2013"]], "month": [["01"]], "day": [["05"]], "hour": [["04"]], "minute": [["04"]], "second": [["39"]], "millis": [["398"] ], "loglevel": [ ["INFO"]] }

你能帮我解析一下吗?

1 个答案:

答案 0 :(得分:1)

刚试过这个配置。我有点复制了你问题中的所有内容。

input {
  stdin { type => "edai" }
}

filter {
  if [type] == "edai" {
    grok {
      match => { "message" => ["%{YEAR:year}-%{WORD:month}-%{DATA:day} %{DATA:hour}:%{DATA:minute}:%{DATA:second},%{DATA:millis} %{NOTSPACE:loglevel} {0,1}%{GREEDYDATA:message}"] }
      overwrite => [ "message" ]
    }
  }
}

output {
  stdout { codec => rubydebug }
}

这是输出:

{
          "year" => "2013",
       "message" => " [ajp-bio-8009-exec-69] web.CustomAuthenticationSuccessHandler - doLogin : admin.ebusiness date : 2013-01-05 03:29:38\r",
          "type" => "edai",
        "minute" => "29",
        "second" => "38",
    "@timestamp" => 2017-06-29T08:19:08.605Z,
         "month" => "01",
          "hour" => "03",
      "loglevel" => "INFO",
      "@version" => "1",
          "host" => "host_name",
        "millis" => "842",
           "day" => "05"
}

从我的角度来看,一切似乎都很好。

当我按照你的方式比较时,我遇到了问题:

if [type] in ["eday"]

它不起作用,我用直接比较取而代之:

if [type] == "edai"

这也有效:

if [type] in "edai"

这解决了这个问题。

相关问题