【发布时间】:2017-07-07 14:52:10
【问题描述】:
我正在尝试使用 Logstash 解析 nginx 日志,一切看起来都很好,除了使用包含 Nginx $remote_user 的行获取此 _grokparsefailure 标记。当 $remote_user 为 '-'(未指定 $remote_user 时的默认值)时,Logstash 会完成这项工作,但使用像 user@gmail.com 这样的真正 $remote_user 会失败并放置一个 _grokparsefailure 标签:
127.0.0.1 - - [17/Feb/2017:23:14:08 +0100] "GET /favicon.ico HTTP/1.1" 302 169 "http://training-hub.tn/trainer/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, 像 Gecko) Chrome/56.0.2924.87 Safari/537.36"
=====> 工作正常
127.0.0.1 - jemlifathi@gmail.com [17/Feb/2017:23:14:07 +0100] “GET /trainer/templates/home.tmpl.html HTTP/1.1”304 0 "http://training-hub.tn/trainer/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36(KHTML,像 Gecko)Chrome/56.0.2924.87 Safari/537.36"
=====>_grokparsefailure 标签和解析日志行失败
我正在使用这个配置文件:
input {
file {
path => "/home/dev/node/training-hub/logs/access_log"
start_position => "beginning"
sincedb_path => "/dev/null"
ignore_older => 0
type => "logs"
}
}
filter {
if[type] == "logs" {
mutate {
gsub => ["message", "::ffff:", ""]
}
grok {
match=> [
"message" , "%{COMBINEDAPACHELOG}+%{GREEDYDATA:extra_fields}",
"message" , "%{COMMONAPACHELOG}+%{GREEDYDATA:extra_fields}"
]
overwrite=> [ "message" ]
}
mutate {
convert=> ["response", "integer"]
convert=> ["bytes", "integer"]
convert=> ["responsetime", "float"]
}
geoip {
source => "clientip"
target => "geoip"
database => "/etc/logstash/GeoLite2-City.mmdb"
add_field => [ "[geoip][coordinates]", "%{[geoip][longitude]}" ]
add_field => [ "[geoip][coordinates]", "%{[geoip][latitude]}" ]
}
mutate {
convert => [ "[geoip][coordinates]", "float"]
}
date {
match=> [ "timestamp", "dd/MMM/YYYY:HH:mm:ss Z" ]
remove_field=> [ "timestamp" ]
}
useragent {
source=> "agent"
}
}
}
output { elasticsearch { hosts => "localhost:9200" } }
【问题讨论】:
标签: nginx elasticsearch logstash logstash-grok logstash-configuration