https://github.com/apache/skywalking-nginx-lua
接入前提
1.nginx需支持lua,本文使用openresty,集成nginx lua,安装可参考我的其它文档
2.下载skywalking-nginx-lua sdk 下载地址
openresty安装目录/opt/openresty
将下载的skywalking-nginx-lua-master包解压到/opt/openresty
修改skywalking-nginx-lua-master/examples/nginx.conf
worker_processes 1;
daemon off;
error_log /dev/stdout debug;
events {
worker_connections 1024;
}
http {
lua_package_path "/opt/openresty/skywalking-nginx-lua-master/lib/?.lua;;";
lua_shared_dict tracing_buffer 100m;
init_worker_by_lua_block {
local metadata_buffer = ngx.shared.tracing_buffer
#设置skywalking UI上面的服务名称
metadata_buffer:set('serviceName', 'test-nginx')
-- Instance means the number of Nginx deloyment, does not mean the worker instances
#设置skywalking UI上面的实例名称
metadata_buffer:set('serviceInstanceName', 'nginx')
-- type 'boolean', mark the entrySpan include host/domain
metadata_buffer:set('includeHostInEntrySpan', false)
-- set randomseed
require("skywalking.util").set_randomseed()
#设置skywalking服务端的地址和端口
require("skywalking.client"):startBackendTimer("http://10.36.144.14:12800")
-- Any time you want to stop reporting metrics, call `destroyBackendTimer`
-- require("skywalking.client"):destroyBackendTimer()
-- If there is a bug of this `tablepool` implementation, we can
-- disable it in this way
-- require("skywalking.util").disable_tablepool()
skywalking_tracer = require("skywalking.tracer")
}
server {
listen 8090;
location /ingress {
default_type text/html;
rewrite_by_lua_block {
skywalking_tracer:start("xxx")
-- If you want correlation custom data to the downstream service
-- skywalking_tracer:start("xxx", {custom = "custom_value"})
}
#后端代理服务地址
#proxy_pass http://127.0.0.1:8090/test;
body_filter_by_lua_block {
if ngx.arg[2] then
skywalking_tracer:finish()
end
}
log_by_lua_block {
skywalking_tracer:prepareForReport()
}
content_by_lua_block {
ngx.say("ok")
}
}
}
}
命令行启动nginx
nginx -p `pwd` -c skywalking-nginx-lua-master/examples/nginx.conf
触发接口访问
curl http://127.0.0.1:8090/ingress
查看skywalking已经采集到nginx请求信息了
后续更新集成nginx代理后端微服务链路信息