服务器搭建

ELK --- 配置Nginx访问日志

2017-01-09  本文已影响206人  梦想做小猿

说明

因为nginx可以自定义访问日志,而logstash处理json格式日志比较方便,所以可以先将nginx访问日志格式手动拼成json格式

修改nginx访问日志格式

http {
    log_format json '{"@timestamp":"$time_iso8601",'
                    '"host":"$server_addr",'
                    '"clientip":"$remote_addr",'
                    '"size":"body_bytes_sent",'
                    '"responsetime":$request_time,'
                    '"upstreamtime":"$upstream_response_time",'
                    '"upstreamhost":"$upstream_addr",'
                    '"http_host":"$host",'
                    '"url":"$uri",'
                    '"xff":"$http_x_forwarded_for",'
                    '"referer":"$http_referer",'
                    '"agent":"$http_user_agent",'
                    '"status":"$status"}';
......
}

logstash配置

[root@localhost /usr/local/logstash-5.1.1]# vim config/conf.d/nginx.conf
input {
    file {
        path => "/var/log/nginx/access.log"
        codec => json
    }
}

filter {
    mutate {
        split => ["upstreamtime", ","]
    }
    mutate {
        convert => ["upstreamtime","float"]
    }
}

output {
        elasticsearch {
            hosts => "172.16.11.199"
            index => "logstash-nginx-%{+YYYY.MM.dd}"
        }
}

配置解释:

kibana配置

上一篇 下一篇

猜你喜欢

热点阅读