Logstash+nginx:不会添加字段
我将设置自己的ELK服务器来集中日志记录。到目前为止还不错 我设置docker-compose.yml运行ELK堆栈,另一个docker-compose.yml运行filebeat,它将监视日志文件,添加env+标记并发送到logstash。应该在logstash中进行解析 filebeat.ymlLogstash+nginx:不会添加字段,logstash,elastic-stack,filebeat,Logstash,Elastic Stack,Filebeat,我将设置自己的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: - in
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上测试了这个表达式,它成功了
这里有一个演示行:
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" "-"
但没有添加字段
我想也许我的if是错的,但我尝试了几种选择。。。没有任何帮助
有什么想法吗?我将首先删除if,然后逐个添加条件。那是从
["nginx"] in [tags]
如果这有效的话,那就去
["nginx"] in [tags] and ["access"] in [tags]
或者,您可以尝试使用
"nginx" in [tags] and "access" in [tags]
更新:
要使用fields.type=nginx访问,请重试
"nginx-access" in [fields][type]
感谢男士:如果[tags]中的nginx和[tags]中的access{很好用!很高兴能为您提供帮助。您知道if条件如何适应字段。type=nginx access?