[prometheus] add blskeys metric

Signed-off-by: Leo Chen <leo@harmony.one>
pull/3466/head
Leo Chen 4 years ago
parent 6b5e84dda0
commit 85ea84715f
  1. 1
      consensus/consensus.go
  2. 23
      consensus/metrics.go

@ -224,6 +224,7 @@ func New(
// init prometheus metrics
initMetrics()
consensus.AddPubkeyMetrics()
return &consensus, nil
}

@ -1,6 +1,7 @@
package consensus
import (
"fmt"
"sync"
prom "github.com/harmony-one/harmony/api/service/prometheus"
@ -56,6 +57,18 @@ var (
"consensus",
},
)
// consensusPubkeyVec is used to keep track of bls pubkeys
consensusPubkeyVec = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: "hmy",
Subsystem: "consensus",
Name: "blskeys",
Help: "list of bls pubkey",
},
[]string{
"index", "pubkey",
},
)
// consensusFinalityHistogram is used to keep track of finality
// 10 ExponentialBuckets are in the unit of millisecond:
// 800, 1000, 1250, 1562, 1953, 2441, 3051, 3814, 4768, 5960, inf
@ -91,6 +104,15 @@ func (consensus *Consensus) UpdateLeaderMetrics(numCommits float64, blockNum flo
consensusGaugeVec.With(prometheus.Labels{"consensus": "num_commits"}).Set(numCommits)
}
// AddPubkeyMetrics add the list of blskeys to prometheus metrics
func (consensus *Consensus) AddPubkeyMetrics() {
keys := consensus.GetPublicKeys()
for i, key := range keys {
index := fmt.Sprintf("%d", i)
consensusPubkeyVec.With(prometheus.Labels{"index": index, "pubkey": key.Bytes.Hex()}).Set(float64(i))
}
}
func initMetrics() {
onceMetrics.Do(func() {
prom.PromRegistry().MustRegister(
@ -98,6 +120,7 @@ func initMetrics() {
consensusVCCounterVec,
consensusSyncCounterVec,
consensusGaugeVec,
consensusPubkeyVec,
consensusFinalityHistogram,
)
})

Loading…
Cancel
Save