mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 11:07:56 +00:00
Add lots of networking metrics for Prometheus (#5126)
* Add some metrics * Address concerns
This commit is contained in:
@@ -191,6 +191,20 @@ impl PeerState {
|
||||
PeerState::Incoming { .. } => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// True if that node has been requested by the PSM.
|
||||
fn is_requested(&self) -> bool {
|
||||
match self {
|
||||
PeerState::Poisoned => false,
|
||||
PeerState::Banned { .. } => false,
|
||||
PeerState::PendingRequest { .. } => true,
|
||||
PeerState::Requested => true,
|
||||
PeerState::Disabled { .. } => false,
|
||||
PeerState::DisabledPendingEnable { .. } => true,
|
||||
PeerState::Enabled { .. } => true,
|
||||
PeerState::Incoming { .. } => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// State of an "incoming" message sent to the peer set manager.
|
||||
@@ -277,6 +291,11 @@ impl GenericProto {
|
||||
self.notif_protocols.push((protocol_name.into(), engine_id, handshake_msg.into()));
|
||||
}
|
||||
|
||||
/// Returns the number of discovered nodes that we keep in memory.
|
||||
pub fn num_discovered_peers(&self) -> usize {
|
||||
self.peerset.num_discovered_peers()
|
||||
}
|
||||
|
||||
/// Returns the list of all the peers we have an open channel to.
|
||||
pub fn open_peers<'a>(&'a self) -> impl Iterator<Item = &'a PeerId> + 'a {
|
||||
self.peers.iter().filter(|(_, state)| state.is_open()).map(|(id, _)| id)
|
||||
@@ -360,6 +379,11 @@ impl GenericProto {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the list of all the peers that the peerset currently requests us to be connected to.
|
||||
pub fn requested_peers<'a>(&'a self) -> impl Iterator<Item = &'a PeerId> + 'a {
|
||||
self.peers.iter().filter(|(_, state)| state.is_requested()).map(|(id, _)| id)
|
||||
}
|
||||
|
||||
/// Returns true if we try to open protocols with the given peer.
|
||||
pub fn is_enabled(&self, peer_id: &PeerId) -> bool {
|
||||
match self.peers.get(peer_id) {
|
||||
|
||||
Reference in New Issue
Block a user