-
Notifications
You must be signed in to change notification settings - Fork 4.7k
feat: metrics including pprof and expvars #1000
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Thanks for your great effort! It seems to me the code is well written. I'm curious to hear what other project participants think about this. |
This comment was marked as outdated.
This comment was marked as outdated.
|
Thank you for your reply.
Prometheus client has been widely used in many projects, including similar anti-censorship tools like hysteria. It does not do more than formatting some numbers to a specific format so I don't assume that would be too vulnerable. If you are really concerned about involving external dependencies I could add only
Personally I think observability as a feature is
Even if you don't need that feature, you could just turn it off and it won't do any harm at all. |
|
I've removed prometheus related code from my commit. That part could be discussed later as another merge request. At the same time I've added code to expose stats and observatory data via |
|
Thanks for the update! I will do some test on my side tomorrow and update you if I see anything need change. |
|
Added some more detailed description about |
|
Looks great to me! Thanks for your work and thorough documentation! |
|
step 1 2 3 done |
A more straightforward (and hopefully better) way to export stats.
Enabling metrics
Quite similar to how to enable Xray APIs
metricswithtag(outbound tag) as its only configuration{ "metrics": { "tag": "metrics_out" } }127.0.0.1:11111{ "port": 11111, "protocol": "dokodemo-door", "tag": "metrics_in", "settings": { "address": "127.0.0.1" }, "listen": "127.0.0.1" }{ "type": "field", "inboundTag": [ "metrics_in" ], "outboundTag": "metrics_out" }Usage
pprof
Access
http://127.0.0.1:11111/debug/pprof/or usego tool pprofto start profiling or inspect running goroutines.expvars
Access
http://127.0.0.1:11111/debug/varsVariables exported include:
statsincludes statistics about inbounds, outbounds and usersobservatoryincludes observatory resultsfor example with luci-app-xray you are likely to get a result like this (standard expvar things like
cmdlineandmemstatsare omitted){ "observatory": { "tcp_outbound": { "alive": true, "delay": 782, "outbound_tag": "tcp_outbound", "last_seen_time": 1648477189, "last_try_time": 1648477189 }, "udp_outbound": { "alive": true, "delay": 779, "outbound_tag": "udp_outbound", "last_seen_time": 1648477191, "last_try_time": 1648477191 } }, "stats": { "inbound": { "api": { "downlink": 0, "uplink": 0 }, "dns_server_inbound_5300": { "downlink": 14286, "uplink": 5857 }, "http_inbound": { "downlink": 74460, "uplink": 10231 }, "https_inbound": { "downlink": 0, "uplink": 0 }, "metrics": { "downlink": 6327, "uplink": 1347 }, "socks_inbound": { "downlink": 19925615, "uplink": 5512 }, "tproxy_tcp_inbound": { "downlink": 4739161, "uplink": 1568869 }, "tproxy_udp_inbound": { "downlink": 0, "uplink": 2608142 } }, "outbound": { "blackhole_outbound": { "downlink": 0, "uplink": 0 }, "direct": { "downlink": 97714548, "uplink": 3234617 }, "dns_server_outbound": { "downlink": 7116, "uplink": 2229 }, "manual_tproxy_outbound_tcp_1": { "downlink": 0, "uplink": 0 }, "manual_tproxy_outbound_udp_1": { "downlink": 0, "uplink": 0 }, "tcp_outbound": { "downlink": 23873238, "uplink": 1049595 }, "udp_outbound": { "downlink": 639282, "uplink": 74634 } }, "user": {} } }To get a better view of these numbers, Netdata (with python.d plugin) is a great option:
sudo /etc/netdata/edit-config python.d/go_expvar.conf)And you will get a nice plot like this:
Additional
Maybe reusing the empty object
statsin config file is better than addingmetricshere?Edit: removed prometheus related things and added usage about expvars