Skip to content

Commit

Permalink
feat: expose produced endorsements (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
MattKetmo authored Aug 20, 2024
1 parent 73e8bc0 commit 108b54f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 24 deletions.
52 changes: 34 additions & 18 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,26 @@ import (
)

type Metrics struct {
BlockNumber prometheus.Gauge
ChainID *prometheus.GaugeVec
CurrentProposals *prometheus.GaugeVec
EpochLength prometheus.Gauge
EpochStartHeight prometheus.Gauge
NextValidatorStake *prometheus.GaugeVec
PrevEpochKickout *prometheus.GaugeVec
ProtocolVersion prometheus.Gauge
SeatPrice prometheus.Gauge
SyncingDesc prometheus.Gauge
ValidatorExpectedBlocks *prometheus.GaugeVec
ValidatorExpectedChunks *prometheus.GaugeVec
ValidatorProducedBlocks *prometheus.GaugeVec
ValidatorProducedChunks *prometheus.GaugeVec
ValidatorSlashed *prometheus.GaugeVec
ValidatorStake *prometheus.GaugeVec
ValidatorRank *prometheus.GaugeVec
VersionBuild *prometheus.GaugeVec
BlockNumber prometheus.Gauge
ChainID *prometheus.GaugeVec
CurrentProposals *prometheus.GaugeVec
EpochLength prometheus.Gauge
EpochStartHeight prometheus.Gauge
NextValidatorStake *prometheus.GaugeVec
PrevEpochKickout *prometheus.GaugeVec
ProtocolVersion prometheus.Gauge
SeatPrice prometheus.Gauge
SyncingDesc prometheus.Gauge
ValidatorExpectedBlocks *prometheus.GaugeVec
ValidatorExpectedChunks *prometheus.GaugeVec
ValidatorExpectedEndorsements *prometheus.GaugeVec
ValidatorProducedBlocks *prometheus.GaugeVec
ValidatorProducedChunks *prometheus.GaugeVec
ValidatorProducedEndorsements *prometheus.GaugeVec
ValidatorSlashed *prometheus.GaugeVec
ValidatorStake *prometheus.GaugeVec
ValidatorRank *prometheus.GaugeVec
VersionBuild *prometheus.GaugeVec
}

func New(namespace string) *Metrics {
Expand Down Expand Up @@ -94,6 +96,12 @@ func New(namespace string) *Metrics {
Help: "Current amount of validator expected chunks"},
[]string{"account_id", "public_key", "epoch_start_height", "tracked"},
),
ValidatorExpectedEndorsements: prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: namespace,
Name: "validator_endorsements_expected",
Help: "Current amount of validator expected endorsements"},
[]string{"account_id", "public_key", "epoch_start_height", "tracked"},
),
ValidatorProducedBlocks: prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: namespace,
Name: "validator_blocks_produced",
Expand All @@ -106,6 +114,12 @@ func New(namespace string) *Metrics {
Help: "Current amount of validator produced chunks"},
[]string{"account_id", "public_key", "epoch_start_height", "tracked"},
),
ValidatorProducedEndorsements: prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: namespace,
Name: "validator_endorsements_produced",
Help: "Current amount of validator produced endorsements"},
[]string{"account_id", "public_key", "epoch_start_height", "tracked"},
),
ValidatorSlashed: prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: namespace,
Name: "validator_slashed",
Expand Down Expand Up @@ -149,8 +163,10 @@ func (m *Metrics) Register(reg prometheus.Registerer) {
reg.MustRegister(m.SyncingDesc)
reg.MustRegister(m.ValidatorExpectedBlocks)
reg.MustRegister(m.ValidatorExpectedChunks)
reg.MustRegister(m.ValidatorExpectedEndorsements)
reg.MustRegister(m.ValidatorProducedBlocks)
reg.MustRegister(m.ValidatorProducedChunks)
reg.MustRegister(m.ValidatorProducedEndorsements)
reg.MustRegister(m.ValidatorSlashed)
reg.MustRegister(m.ValidatorStake)
reg.MustRegister(m.ValidatorRank)
Expand Down
14 changes: 8 additions & 6 deletions pkg/near/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import (
type ValidatorsResponse struct {
CurrentValidators []struct {
Validator
IsSlashed bool `json:"is_slashed"`
Shards []int `json:"shards"`
NumProducedBlocks int64 `json:"num_produced_blocks"`
NumExpectedBlocks int64 `json:"num_expected_blocks"`
NumProducedChunks int64 `json:"num_produced_chunks"`
NumExpectedChunks int64 `json:"num_expected_chunks"`
IsSlashed bool `json:"is_slashed"`
Shards []int `json:"shards"`
NumProducedBlocks int64 `json:"num_produced_blocks"`
NumExpectedBlocks int64 `json:"num_expected_blocks"`
NumProducedChunks int64 `json:"num_produced_chunks"`
NumExpectedChunks int64 `json:"num_expected_chunks"`
NumProducedEndorsements int64 `json:"num_produced_endorsements"`
NumExpectedEndorsements int64 `json:"num_expected_endorsements"`
} `json:"current_validators"`
NextValidators []struct {
Validator
Expand Down
4 changes: 4 additions & 0 deletions pkg/watcher/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,10 @@ func (w *Watcher) collectValidators(ctx context.Context) (near.ValidatorsRespons
// Reset labeled gauge vec
w.metrics.ValidatorExpectedBlocks.Reset()
w.metrics.ValidatorExpectedChunks.Reset()
w.metrics.ValidatorExpectedEndorsements.Reset()
w.metrics.ValidatorProducedBlocks.Reset()
w.metrics.ValidatorProducedChunks.Reset()
w.metrics.ValidatorProducedEndorsements.Reset()
w.metrics.ValidatorSlashed.Reset()
w.metrics.ValidatorStake.Reset()
w.metrics.ValidatorRank.Reset()
Expand Down Expand Up @@ -158,8 +160,10 @@ func (w *Watcher) collectValidators(ctx context.Context) (near.ValidatorsRespons

w.metrics.ValidatorExpectedBlocks.WithLabelValues(labels...).Set(float64(v.NumExpectedBlocks))
w.metrics.ValidatorExpectedChunks.WithLabelValues(labels...).Set(float64(v.NumExpectedChunks))
w.metrics.ValidatorExpectedEndorsements.WithLabelValues(labels...).Set(float64(v.NumExpectedEndorsements))
w.metrics.ValidatorProducedBlocks.WithLabelValues(labels...).Set(float64(v.NumProducedBlocks))
w.metrics.ValidatorProducedChunks.WithLabelValues(labels...).Set(float64(v.NumProducedChunks))
w.metrics.ValidatorProducedEndorsements.WithLabelValues(labels...).Set(float64(v.NumProducedEndorsements))

w.metrics.ValidatorSlashed.WithLabelValues(labels...).Set(metrics.BoolToFloat64(v.IsSlashed))
w.metrics.ValidatorStake.WithLabelValues(labels...).Set(v.Stake.Div(yoctoUnit).InexactFloat64())
Expand Down

0 comments on commit 108b54f

Please sign in to comment.