paritytech / jsonrpc

Rust JSON-RPC implementation
MIT License
790 stars 274 forks source link

Monitoring number of current connections #239

Open bbqsrc opened 6 years ago

bbqsrc commented 6 years ago

Is it possible to monitor the number of connections to a TCP server currently?

I need to be able to detect once the number of connections has dropped to zero to do some cleanup, and I am at a loss to work out how to do that.

tomusdrw commented 6 years ago

We support session counting for WS and IPC servers: https://paritytech.github.io/jsonrpc/jsonrpc_ws_server/trait.SessionStats.html

It's implemented as Drop of Session object: https://github.com/paritytech/jsonrpc/blob/786f3e16ba6192a42955eddf57e4baa2a57dde3b/ws/src/session.rs#L155

AFAICT it's not possible currently in TCP server, but I'm open for help in implementing that. You could possibly have a custom Metadata and count session using this, but you need to ensure that the method implementation is storing the metadata for as long as the session object.