From 55a294a5c9143921c4dba6c3b10dcb352be3b927 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Thu, 11 Jun 2020 12:09:34 -0600 Subject: [PATCH] better pubsub metrics (#214) --- libp2p/protocols/pubsub/gossipsub.nim | 40 +++++++++++++------------- libp2p/protocols/pubsub/pubsubpeer.nim | 19 ++++++------ 2 files changed, 29 insertions(+), 30 deletions(-) diff --git a/libp2p/protocols/pubsub/gossipsub.nim b/libp2p/protocols/pubsub/gossipsub.nim index ae022cf..85c3fd4 100644 --- a/libp2p/protocols/pubsub/gossipsub.nim +++ b/libp2p/protocols/pubsub/gossipsub.nim @@ -83,7 +83,7 @@ proc replenishFanout(g: GossipSub, topic: string) {.async.} = if topic in g.gossipsub: for p in g.gossipsub[topic]: if not g.fanout[topic].containsOrIncl(p): - libp2p_gossipsub_peers_per_topic_fanout.inc(labelValues = [topic]) + libp2p_gossipsub_peers_per_topic_fanout.set(g.fanout[topic].len.int64, labelValues = [topic]) if g.fanout[topic].len == GossipSubD: break @@ -105,19 +105,19 @@ proc rebalanceMesh(g: GossipSub, topic: string) {.async.} = if topic in g.fanout and g.fanout[topic].len > 0: id = sample(toSeq(g.fanout[topic])) g.fanout[topic].excl(id) - libp2p_gossipsub_peers_per_topic_fanout.dec(labelValues = [topic]) + libp2p_gossipsub_peers_per_topic_fanout.set(g.fanout[topic].len.int64, labelValues = [topic]) trace "got fanout peer", peer = id elif topic in g.gossipsub and g.gossipsub[topic].len > 0: id = sample(toSeq(g.gossipsub[topic])) g.gossipsub[topic].excl(id) - libp2p_gossipsub_peers_per_topic_gossipsub.dec(labelValues = [topic]) + libp2p_gossipsub_peers_per_topic_gossipsub.set(g.gossipsub[topic].len.int64, labelValues = [topic]) trace "got gossipsub peer", peer = id else: trace "no more peers" break g.mesh[topic].incl(id) - libp2p_gossipsub_peers_per_topic_mesh.inc(labelValues = [topic]) + libp2p_gossipsub_peers_per_topic_mesh.set(g.mesh[topic].len.int64, labelValues = [topic]) if id in g.peers: let p = g.peers[id] # send a graft message to the peer @@ -130,13 +130,13 @@ proc rebalanceMesh(g: GossipSub, topic: string) {.async.} = trace "pruning peers", peers = g.mesh[topic].len let id = toSeq(g.mesh[topic])[rand(0..