一、nginx訪問日誌,格式調整爲json
# cat /opt/config/tengine/nginx.conf |grep json
log_format json '{"@timestamp":"$time_iso8601",'
'"host":"$server_addr",'
'"method":"$request_method",'
'"url":"$request",'
'"clientip":"$http_x_forwarded_for",'
'"protocol":"$server_protocol",'
'"useragent":"$http_user_agent",'
'"referer":"$http_referer",'
'"http_host":"$host",'
'"status":"$status",'
'"size":"$body_bytes_sent",'
'"responsetime":"$request_time",'
'"visitorid":"$51autoVisitorId"}';
二、配置logstash,日誌收集、處理、存儲
cat /opt/config/logstash/www-nginx-access.conf
input {
file {
path => "/opt/logs/tengine/www.51auto.com.log"
type => "nginx-access"
start_position => "beginning"
codec => "json"
}
}
filter {
mutate {
convert => ["size","float"]
convert => ["status","float"]
}
}
output {
if [type] == "nginx-access" {
elasticsearch {
hosts => ["xxxxx:9200","xxxxx:9200"]
index => "www-nginx-access-%{+YYYY-MM}"
}
}
}
三、elasticseach查看收集上來的索引信息
四、kibana報表展示,是不是很漂亮。。