ELK-Logstash Nginx 日志分析
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ELK-Logstash Nginx 日志分析相关的知识,希望对你有一定的参考价值。
logstash配置文件
# nginx_log.conf
input {
file
{
type
=>
"nginx_log"
path =>
"/opt/nginx/logs/access.log"
}
}
filter {
if
[
type
] ==
"nginx_log"
{
grok {
match => {
"message"
=>
"%{NGINXACCESS}"
}
}
if
([message] =~
"^*launcher*|^*favicon*"
) {
drop {}
}
geoip {
source
=>
"remote_addr"
target =>
"geoip"
database =>
"/opt/logstash-2.0.0/conf/GeoLiteCity.dat"
add_field => [
"[geoip][coordinates]"
,
"%{[geoip][longitude]}"
]
add_field => [
"[geoip][coordinates]"
,
"%{[geoip][latitude]}"
]
}
mutate {
convert => [
"[geoip][coordinates]"
,
"float"
,
"body_bytes_sent"
,
"float"
, \
"body_bytes_sent.raw"
,
"float"
]
}
}
}
output {
stdout { codec => rubydebug }
elasticsearch {
hosts =>
"192.168.0.100:9200"
index =>
"ngx_log-%{+YYYY.MM}"
}
}
NGINXACCESS 定义,可写在patterns/nginx 文件里
NGUSERNAME [a-zA-Z\.\@\-\+_%]+
NGUSER %{NGUSERNAME}
NGINXACCESS %{IPORHOST:remote_addr} - - \[%{HTTPDATE:time_local}\] "%{WORD:method} %{URIPATHPARAM:request} HTTP/%{NUMBER:httpversion}" %{INT:status} %{INT:body_bytes_sent} %{QS:http_referer} %{QS:http_user_agent}
kibana 形图展示
以上是关于ELK-Logstash Nginx 日志分析的主要内容,如果未能解决你的问题,请参考以下文章