Logstash Nginx过滤器不适用于一半的行

时间:2018-09-22 10:55:13

标签: elasticsearch nginx logstash filebeat

使用filebeat将nginx日志推送到logstash,然后推送到elasticsearch。

Logstash过滤器:

    filter {
      if [fileset][module] == "nginx" {
        if [fileset][name] == "access" {
          grok {
            match => { "message" => ["%{IPORHOST:[nginx][access][remote_ip]} - %{DATA:[nginx][access][user_name]} \[%{HTTPDATE:[nginx][access][time]}\] \"%{WORD:[nginx][access][method]} %{DATA:[nginx][access][url]} HTTP/%{NUMBER:[nginx][access][http_version]}\" %{NUMBER:[nginx][access][response_code]} %{NUMBER:[nginx][access][body_sent][bytes]} \"%{DATA:[nginx][access][referrer]}\" \"%{DATA:[nginx][access][agent]}\""] }
            remove_field => "message"
          }
          mutate {
            add_field => { "read_timestamp" => "%{@timestamp}" }
          }
          date {
            match => [ "[nginx][access][time]", "dd/MMM/YYYY:H:m:s Z" ]
            remove_field => "[nginx][access][time]"
          }
          useragent {
            source => "[nginx][access][agent]"
            target => "[nginx][access][user_agent]"
            remove_field => "[nginx][access][agent]"
          }
          geoip {
            source => "[nginx][access][remote_ip]"
            target => "[nginx][access][geoip]"
          }
        }
        else if [fileset][name] == "error" {
          grok {
            match => { "message" => ["%{DATA:[nginx][error][time]} \[%{DATA:[nginx][error][level]}\] %{NUMBER:[nginx][error][pid]}#%{NUMBER:[nginx][error][tid]}: (\*%{NUMBER:[nginx][error][connection_id]} )?%{GREEDYDATA:[nginx][error][message]}"] }
            remove_field => "message"
          }
          mutate {
            rename => { "@timestamp" => "read_timestamp" }
          }
          date {
            match => [ "[nginx][error][time]", "YYYY/MM/dd H:m:s" ]
            remove_field => "[nginx][error][time]"
          }
        }
      }
    }

只有一个文件/var/log/nginx/access.log。 在kibana中,我看到±一半的行具有已解析的消息,而另一半则没有-

kibana中的所有行都带有标签“ beats_input_codec_plain_applied”。

来自filebeat -e

的示例

行正常:

    "source": "/var/log/nginx/access.log",
    "offset": 5405195,
    "message": "...",
    "fileset": {
        "module": "nginx",
        "name": "access"
    }

行不通(没有“文件集”):

    "offset": 5405397,
    "message": "...",
    "source": "/var/log/nginx/access.log"

你知道是什么原因吗?

0 个答案:

没有答案