open_resty + elk實(shí)現(xiàn)客戶端日志上報(bào)、展示功能

open_resty + elk實(shí)現(xiàn)客戶端日志上報(bào)和展示功能
整個(gè)功能框圖如下:


屏幕快照 2017-02-21 上午11.03.41.png

相關(guān)知識(shí)點(diǎn):

1. open_resty
2. elk

主要過程:
1.客戶端post錯(cuò)誤信息到open_resty監(jiān)聽的url,打印請(qǐng)求的結(jié)構(gòu)體到nginx的error_log里面
2.log_stash監(jiān)聽error_log,把文件內(nèi)容同步到elastic_search里面;
3.通過kibana來查看錯(cuò)誤日志

實(shí)現(xiàn):

  1. nginx配置文件
    <pre>
    worker_processes 1;
    error_log logs/error.log;
    events {
    worker_connections 1024;
    }
    http {
    server {
    listen 3030;
    location /report {
    content_by_lua_block {
    local cjson = require("cjson")
    ngx.req.read_body()
    local arg = ngx.req.get_post_args()
    ngx.log(ngx.ERR,cjson.encode(arg)) #body就是錯(cuò)誤信息,打 # 印到log里面
    }
    }
    }
    }
    </pre>

  2. log_stash配置文件

<pre>
input {
file {
path => "/home/dhcd/nginx/logs/error.log"
start_position => beginning
}
}
filter {

}
output {
elasticsearch {
hosts => ["172.30.0.219:9200"]
index => "app_error"
}
}
</pre>

3.在kibana里面建立一個(gè)app_error的indice就可以了。日志是實(shí)時(shí)的

屏幕快照 2017-02-21 上午11.23.18.png
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容