Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions crates/networking/p2p/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ pub struct Metrics {
pub peers: Arc<Mutex<u64>>,
/// The amount of clients connected grouped by client type
pub peers_by_client_type: Arc<Mutex<BTreeMap<String, u64>>>,
/// Ex-peers.
pub disconnections: Arc<Mutex<BTreeMap<String, u64>>>,
/// Ex-peers by client type and then reason of disconnection.
pub disconnections_by_client_type: Arc<Mutex<BTreeMap<String, BTreeMap<String, u64>>>>,
/// RLPx connection attempt failures grouped and counted by reason
pub connection_attempt_failures: Arc<Mutex<BTreeMap<String, u64>>>,

Expand Down Expand Up @@ -106,20 +106,25 @@ impl Metrics {
) {
*self.peers.lock().await -= 1;

self.disconnections
.lock()
.await
.entry(reason.to_string())
.and_modify(|e| *e += 1)
.or_insert(1);

let mut clients = self.peers_by_client_type.lock().await;
let split = client_version.split('/').collect::<Vec<&str>>();
let client_type = split.first().expect("Split always returns 1 element");

clients
.entry(client_type.to_string())
.and_modify(|count| *count -= 1);

let mut disconnection_by_client = self.disconnections_by_client_type.lock().await;
disconnection_by_client
.entry(client_type.to_string())
.or_insert(BTreeMap::new())
.entry(reason.to_string())
.and_modify(|e| *e += 1)
.or_insert(1);

clients
.entry(client_type.to_string())
.and_modify(|count| *count -= 1);
}

pub async fn record_new_rlpx_conn_failure(&self, reason: RLPxError) {
Expand Down Expand Up @@ -413,7 +418,7 @@ impl Default for Metrics {
peers: Arc::new(Mutex::new(0)),
peers_by_client_type: Arc::new(Mutex::new(BTreeMap::new())),

disconnections: Arc::new(Mutex::new(BTreeMap::new())),
disconnections_by_client_type: Arc::new(Mutex::new(BTreeMap::new())),

connection_attempt_failures: Arc::new(Mutex::new(BTreeMap::new())),

Expand Down
7 changes: 5 additions & 2 deletions crates/networking/p2p/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ pub async fn periodically_show_peer_stats() {
let rlpx_connection_failures = METRICS.connection_attempt_failures.lock().await;
let rlpx_connection_client_types = METRICS.peers_by_client_type.lock().await;

let rlpx_disconnections = METRICS.disconnections.lock().await;
let rlpx_disconnections = METRICS.disconnections_by_client_type.lock().await;

info!(
r#"
Expand All @@ -189,7 +189,10 @@ RLPx connection failures: {rlpx_connection_failures_grouped_and_counted_by_reaso
peers = METRICS.peers.lock().await,
new_peers_rate = METRICS.new_connection_establishments_rate.get().floor(),
peers_by_client = rlpx_connection_client_types,
lost_peers = rlpx_disconnections.values().sum::<u64>(),
lost_peers = rlpx_disconnections
.values()
.flat_map(|x| x.values())
.sum::<u64>(),
rlpx_connections = METRICS.connection_establishments.get(),
rlpx_connection_attempts = METRICS.connection_attempts.get(),
new_rlpx_connection_attempts_rate = METRICS.new_connection_attempts_rate.get().floor(),
Expand Down
Loading