From e4968029435b44fcd8401e2acad5731b6a42eb96 Mon Sep 17 00:00:00 2001 From: Giovanni Petrantoni <7008900+sinkingsugar@users.noreply.github.com> Date: Wed, 4 Nov 2020 23:18:00 +0900 Subject: [PATCH] Least expensive metrics (#421) * add more general and useful metrics * fix gossipsub peers metrics in heartbeat --- libp2p/protocols/pubsub/gossipsub.nim | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/libp2p/protocols/pubsub/gossipsub.nim b/libp2p/protocols/pubsub/gossipsub.nim index b5b03669a..dd761cf51 100644 --- a/libp2p/protocols/pubsub/gossipsub.nim +++ b/libp2p/protocols/pubsub/gossipsub.nim @@ -165,6 +165,9 @@ when defined(libp2p_expensive_metrics): "gossipsub peers per topic in gossipsub", labels = ["topic"]) +declareGauge(libp2p_gossipsub_peers_mesh_sum, "pubsub peers in mesh table summed") +declareGauge(libp2p_gossipsub_peers_gossipsub_sum, "pubsub peers in gossipsub table summed") + proc init*(_: type[GossipSubParams]): GossipSubParams = GossipSubParams( explicit: true, @@ -768,11 +771,18 @@ proc heartbeat(g: GossipSub) {.async.} = g.updateScores() + var + totalMeshPeers = 0 + totalGossipPeers = 0 for t in toSeq(g.topics.keys): # prune every negative score peer # do this before relance # in order to avoid grafted -> pruned in the same cycle let meshPeers = g.mesh.getOrDefault(t) + let gossipPeers = g.gossipsub.getOrDefault(t) + # this will be changed by rebalance but does not matter + totalMeshPeers += meshPeers.len + totalGossipPeers += gossipPeers.len var prunes: seq[PubSubPeer] for peer in meshPeers: if peer.score < 0.0: @@ -787,6 +797,9 @@ proc heartbeat(g: GossipSub) {.async.} = g.broadcast(prunes, prune) await g.rebalanceMesh(t) + + libp2p_gossipsub_peers_mesh_sum.set(totalMeshPeers.int64) + libp2p_gossipsub_peers_gossipsub_sum.set(totalGossipPeers.int64) g.dropFanoutPeers()