Skip to content

Commit

Permalink
add metric for peer name
Browse files Browse the repository at this point in the history
  • Loading branch information
xenowits committed Aug 31, 2022
1 parent 291e753 commit ee8f817
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func Run(ctx context.Context, conf Config) (err error) { //nolint:nonamedreturn
"cluster_peer_name": p2p.PeerName(tcpNode.ID()),
}, prometheus.DefaultRegisterer)
}
initStartupMetrics(lockHashHex, lock.Threshold, len(lock.Operators))
initStartupMetrics(lockHashHex, p2p.PeerName(tcpNode.ID()), lock.Threshold, len(lock.Operators))

eth2Cl, err := newETH2Client(ctx, conf, life, lock.Validators)
if err != nil {
Expand Down
9 changes: 8 additions & 1 deletion app/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ var (
Help: "Constant gauge with label set to number of validators in the cluster",
}, []string{"num_validators"})

peerNameGauge = promauto.NewGaugeVec(prometheus.GaugeOpts{
Namespace: "app",
Name: "peer_name",
Help: "Constant gauge with label set to the name of the cluster peer",
}, []string{"peer_name"})

gitGauge = promauto.NewGaugeVec(prometheus.GaugeOpts{
Namespace: "app",
Name: "git_commit",
Expand All @@ -69,7 +75,7 @@ var (
})
)

func initStartupMetrics(lockHash string, threshold, numValidators int) {
func initStartupMetrics(lockHash, peerName string, threshold, numValidators int) {
versionGauge.WithLabelValues(version.Version).Set(1)
startGauge.SetToCurrentTime()

Expand All @@ -78,4 +84,5 @@ func initStartupMetrics(lockHash string, threshold, numValidators int) {
lockHashGauge.WithLabelValues(lockHash).Set(1)
thresholdGauge.WithLabelValues(fmt.Sprintf("%d", threshold)).Set(1)
numValidatorsGauge.WithLabelValues(fmt.Sprintf("%d", numValidators)).Set(1)
peerNameGauge.WithLabelValues(peerName).Set(1)
}

0 comments on commit ee8f817

Please sign in to comment.