elkstack實戰---集中管理nginx訪問日誌及報表展示

一、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查看收集上來的索引信息

wKiom1ds5F_QTGtGAADLQrTN0DA650.png-wh_50


四、kibana報表展示,是不是很漂亮。。

wKiom1ds5SGieUpkAAHDGBnNYMw911.png-wh_50

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章