diff --git a/substrate/client/rpc-servers/src/middleware/metrics.rs b/substrate/client/rpc-servers/src/middleware/metrics.rs index c2d1956c3b39..c0750153346d 100644 --- a/substrate/client/rpc-servers/src/middleware/metrics.rs +++ b/substrate/client/rpc-servers/src/middleware/metrics.rs @@ -136,6 +136,18 @@ impl RpcMetrics { pub(crate) fn ws_connect(&self) { self.ws_sessions_opened.as_ref().map(|counter| counter.inc()); + if let Some(ws_sessions_opened) = &self.ws_sessions_opened { + if let Some(ws_sessions_closed) = &self.ws_sessions_closed { + let active_connections = ws_sessions_opened.get() - ws_sessions_closed.get(); + log::info!( + target: "rpc_metrics", + "{{ \"wsSessionsOpened\": {:?}, \"activeConnections\": {:?} }}", + ws_sessions_opened.get(), + active_connections + ); + } + } + } pub(crate) fn ws_disconnect(&self, now: Instant) { @@ -143,6 +155,18 @@ impl RpcMetrics { self.ws_sessions_closed.as_ref().map(|counter| counter.inc()); self.ws_sessions_time.with_label_values(&["ws"]).observe(micros as _); + + if let Some(ws_sessions_closed) = &self.ws_sessions_closed { + if let Some(ws_sessions_opened) = &self.ws_sessions_opened { + let active_connections = ws_sessions_opened.get() - ws_sessions_closed.get(); + log::info!( + target: "rpc_metrics", + "{{ \"wsSessionsClosed\": {:?}, \"activeConnections\": {:?} }}", + ws_sessions_closed.get(), + active_connections + ); + } + } } }