Skip to content
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

How can I find out the number of connections to the server in interceptor? #761

Closed
blackmarllbor0 opened this issue Jul 1, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@blackmarllbor0
Copy link

To collect metrics I first tried to use otel-connect, but it did not fit the functionality, and I started to make my own interceptor, and faced the problem of getting active connections to the server. How can I find out how many active connections there are now and how can I monitor if a connection has been disconnected?

@blackmarllbor0 blackmarllbor0 added the enhancement New feature or request label Jul 1, 2024
@jhump
Copy link
Member

jhump commented Jul 2, 2024

@blackmarllbor0, nothing in Connect (or even in net/http, if using lower-level middleware) exposes socket details. So if you need to capture that sort of state for metrics or logging, you'd need to provide a custom listener when creating the server, and instrument that listener to handle accepting of new connections. The listener would also need to wrap the accepted net.Conn with a custom implementation that is instrumented to detect when the connection is closed and handle that.

There's a 3rd party library that does exactly this: https://github.com/mwitkow/go-conntrack
Note that we do not have experience with that particular library and don't necessarily endorse it, but it looks like the "right shape" for what you're trying to do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants