【问题标题】:Logstash + nginx: Fields wont be addedLogstash + nginx:不会添加字段
【发布时间】:2017-05-11 12:08:49
【问题描述】:

我将设置我自己的 ELK 服务器来集中日志记录。到目前为止一切顺利。

我设置 docker-compose.yml 来运行 ELK 堆栈和另一个 docker-compose.yml 来运行 filebeat,它将监视日志文件,添加 env + 标签并发送到 logstash。解析应该在logstash中进行。

filebeat.yml

name: xyz

fields:
  env: xyz

output.logstash:
  hosts: ["xyz:5044"]

filebeat.prospectors:
  - input_type: log
    fields:
      app_id: default
      type: nginx-access
    tags:
      - nginx
      - access
    paths:
      - /logs/nginx/access.log*
  - input_type: log
    fields:
      app_id: default
      type: nginx-error
    tags:
      - nginx
      - error
    paths:
      - /logs/nginx/error.log*

这里是 logstash.yml

input {
  beats {
    port => 5044
  }
}

filter {
  if ["nginx"] in [tags] and ["access"] in [tags] {
    grok {
      patterns_dir => "/etc/logstash/patterns"
      match => { "message" => "%{NGINXACCESS}" }
    }

    date {
      match => [ "timestamp", "dd/MMM/YYYY:HH:mm:ss Z" ]
    }
  }
}

output {
  elasticsearch {
    hosts => ["elasticsearch:9200"]
  }
  stdout { codec => rubydebug }
}

nginx 模式在这里

NGUSERNAME [a-zA-Z\.\@\-\+_%]+
NGUSER %{NGUSERNAME}
NGINXACCESS %{IPORHOST:clientip} %{NGUSER:indent} %{NGUSER:agent} \[%{HTTPDATE:timestamp}\] \"(?:%{WORD:verb} %{URIPATHPARAM:request}(?: HTTP/%{NUMBER:httpversion})?|)\" %{NUMBER:answer} (?:%{NUMBER:byte}|-) (?:\"(?:%{URI:referrer}|-))\" (?:%{QS:referree}) %{QS:agent}

我在 grokconstructor.appspot.com 上测试了 Expression,它成功了。

这是一个演示行:

127.0.0.1 - - [11/May/2017:13:49:31 +0200] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Safari/537.36 Edge/13.10586" "-" 

但没有添加任何字段

我认为我的“如果”可能是错误的,但我尝试了几种替代方法......没有任何帮助。

有什么想法吗?

【问题讨论】:

    标签: logstash elastic-stack filebeat


    【解决方案1】:

    我将从删除 if 开始,然后一一添加条件。那是从

    开始
    ["nginx"] in [tags] 
    

    如果行得通,那就去吧

    ["nginx"] in [tags] and ["access"] in [tags]
    

    或者你可以尝试使用

    "nginx" in [tags] and "access" in [tags]
    

    更新:

    要使用fields.type = nginx-access,试试

    "nginx-access" in [fields][type]
    

    【讨论】:

    • 谢谢 :) if "nginx" in [tags] and "access" in [tags] { 工作正常
    • 酷!很高兴能帮上忙。
    • 知道“if”条件必须如何适应fields.type = nginx-access吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多