From fe52bf3b4a86cd785c958d457ba290c631b1dd29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Petrli=C4=87?= Date: Tue, 15 Oct 2024 10:23:01 +0200 Subject: [PATCH] Added logs when ws connections is opened and closed (#19) --- .../rpc-servers/src/middleware/metrics.rs | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) 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 + ); + } + } } }