Add lots of networking metrics for Prometheus (#5126)

* Add some metrics

* Address concerns
This commit is contained in:
Gavin Wood
2020-03-05 21:38:41 +01:00
committed by GitHub
parent dbe0211137
commit d957220435
7 changed files with 220 additions and 23 deletions
@@ -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) {