Skip to content

Commit

Permalink
Add peer gossip score metrics (#3556)
Browse files Browse the repository at this point in the history
  • Loading branch information
twoeths authored Dec 31, 2021
1 parent 240085f commit f49aa8e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/lodestar/src/metrics/metrics/lodestar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,17 @@ export function createLodestarMetrics(
}),
},

gossipPeer: {
scoreByThreshold: register.gauge<"threshold">({
name: "lodestar_gossip_peer_score_by_threshold_count",
help: "Gossip peer score by threashold",
labelNames: ["threshold"],
}),
score: register.avgMinMax({
name: "lodestar_gossip_score_avg_min_max",
help: "Avg min max of all gossip peer scores",
}),
},
gossipMesh: {
peersByType: register.gauge<"type" | "fork">({
name: "lodestar_gossip_mesh_peers_by_type_count",
Expand Down
25 changes: 25 additions & 0 deletions packages/lodestar/src/network/gossip/gossipsub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,31 @@ export class Eth2Gossipsub extends Gossipsub {
}
}
}

// track gossip peer score
let peerCountScoreGraylist = 0;
let peerCountScorePublish = 0;
let peerCountScoreGossip = 0;
let peerCountScoreMesh = 0;
const {graylistThreshold, publishThreshold, gossipThreshold} = gossipScoreThresholds;
const {scoreByThreshold, score: scoreMetric} = metrics.gossipPeer;
const gossipScores = [];

for (const peerIdStr of this.peers.keys()) {
const score = this.score.score(peerIdStr);
if (score >= graylistThreshold) peerCountScoreGraylist++;
if (score >= publishThreshold) peerCountScorePublish++;
if (score >= gossipThreshold) peerCountScoreGossip++;
if (score >= 0) peerCountScoreMesh++;
gossipScores.push(score);
}

scoreByThreshold.set({threshold: "graylist"}, peerCountScoreGraylist);
scoreByThreshold.set({threshold: "publish"}, peerCountScorePublish);
scoreByThreshold.set({threshold: "gossip"}, peerCountScoreGossip);
scoreByThreshold.set({threshold: "mesh"}, peerCountScoreMesh);

scoreMetric.set(gossipScores);
}
}

Expand Down

0 comments on commit f49aa8e

Please sign in to comment.