skywalking监控nginx

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代理后端微服务链路信息

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值