Skip to content

Commit

Permalink
Added logs when ws connections is opened and closed
Browse files Browse the repository at this point in the history
  • Loading branch information
markopoloparadox committed Oct 15, 2024
1 parent f5587b3 commit df5b29d
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions substrate/client/rpc-servers/src/middleware/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,37 @@ 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) {
let micros = now.elapsed().as_secs();

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
);
}
}
}
}

Expand Down

0 comments on commit df5b29d

Please sign in to comment.