mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-06 04:28:01 +00:00
client/network: Expose number of entries per Kademlia bucket (#7104)
Extend `sub_libp2p_kbuckets_num_nodes` Prometheus metric to expose the number of nodes per bucket per Kademlia instance instead of only per Kademlia instance.
This commit is contained in:
@@ -329,10 +329,18 @@ impl DiscoveryBehaviour {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the number of nodes that are in the Kademlia k-buckets.
|
||||
pub fn num_kbuckets_entries(&mut self) -> impl ExactSizeIterator<Item = (&ProtocolId, usize)> {
|
||||
/// Returns the number of nodes in each Kademlia kbucket for each Kademlia instance.
|
||||
///
|
||||
/// Identifies Kademlia instances by their [`ProtocolId`] and kbuckets by the base 2 logarithm
|
||||
/// of their lower bound.
|
||||
pub fn num_entries_per_kbucket(&mut self) -> impl ExactSizeIterator<Item = (&ProtocolId, Vec<(u32, usize)>)> {
|
||||
self.kademlias.iter_mut()
|
||||
.map(|(id, kad)| (id, kad.kbuckets().map(|bucket| bucket.iter().count()).sum()))
|
||||
.map(|(id, kad)| {
|
||||
let buckets = kad.kbuckets()
|
||||
.map(|bucket| (bucket.range().0.ilog2().unwrap_or(0), bucket.iter().count()))
|
||||
.collect();
|
||||
(id, buckets)
|
||||
})
|
||||
}
|
||||
|
||||
/// Returns the number of records in the Kademlia record stores.
|
||||
|
||||
Reference in New Issue
Block a user