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

相關(guān)知識(shí)點(diǎn):
主要過程:
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):
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>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í)的
