Track gossip subscriptions as a metric (#1445)

## Issue Addressed
#1399 

## Proposed Changes
Set an Int gauge per topic and inc/dec when peers subscribe/unsubscribe
This commit is contained in:
divma 2020-08-04 04:18:10 +00:00
parent 31707ccf45
commit 1bbecbcf26
2 changed files with 20 additions and 1 deletions

View File

@ -406,9 +406,23 @@ impl<TSpec: EthSpec> Behaviour<TSpec> {
} }
} }
GossipsubEvent::Subscribed { peer_id, topic } => { GossipsubEvent::Subscribed { peer_id, topic } => {
if let Some(topic_metric) = metrics::get_int_gauge(
&metrics::GOSSIPSUB_SUBSCRIBED_PEERS_COUNT,
&[topic.as_str()],
) {
topic_metric.inc()
}
self.add_event(BehaviourEvent::PeerSubscribed(peer_id, topic)); self.add_event(BehaviourEvent::PeerSubscribed(peer_id, topic));
} }
GossipsubEvent::Unsubscribed { .. } => {} GossipsubEvent::Unsubscribed { peer_id: _, topic } => {
if let Some(topic_metric) = metrics::get_int_gauge(
&metrics::GOSSIPSUB_SUBSCRIBED_PEERS_COUNT,
&[topic.as_str()],
) {
topic_metric.dec()
}
}
} }
} }

View File

@ -34,6 +34,11 @@ lazy_static! {
"Unsolicited discovery requests per ip per second", "Unsolicited discovery requests per ip per second",
&["Addresses"] &["Addresses"]
); );
pub static ref GOSSIPSUB_SUBSCRIBED_PEERS_COUNT: Result<IntGaugeVec> = try_create_int_gauge_vec(
"gossipsub_peers_per_topic_count",
"Peers subscribed per topic",
&["topic_hash"]
);
} }
pub fn scrape_discovery_metrics() { pub fn scrape_discovery_metrics() {