Skip to content

Commit

Permalink
feat: add voting power metric
Browse files Browse the repository at this point in the history
  • Loading branch information
freak12techno committed Mar 13, 2024
1 parent 6e695c5 commit 905db65
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type Manager struct {
missingBlocksGauge *prometheus.GaugeVec
activeBlocksGauge *prometheus.GaugeVec
needsToSignGauge *prometheus.GaugeVec
votingPowerGauge *prometheus.GaugeVec

isActiveGauge *prometheus.GaugeVec
isJailedGauge *prometheus.GaugeVec
Expand Down Expand Up @@ -126,6 +127,10 @@ func NewManager(logger zerolog.Logger, config configPkg.MetricsConfig) *Manager
Name: constants.PrometheusMetricsPrefix + "needs_to_sign",
Help: "Whether the validator needs to sign blocks (for consumer chains)",
}, []string{"chain", "moniker", "address"})
votingPowerGauge := prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: constants.PrometheusMetricsPrefix + "voting_power",
Help: "Voting power % of the validator",
}, []string{"chain", "moniker", "address"})
isActiveGauge := prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: constants.PrometheusMetricsPrefix + "active",
Help: "Whether the validator is active",
Expand Down Expand Up @@ -175,6 +180,7 @@ func NewManager(logger zerolog.Logger, config configPkg.MetricsConfig) *Manager
registry.MustRegister(reconnectsCounter)
registry.MustRegister(missingBlocksGauge)
registry.MustRegister(activeBlocksGauge)
registry.MustRegister(votingPowerGauge)
registry.MustRegister(isActiveGauge)
registry.MustRegister(isJailedGauge)
registry.MustRegister(needsToSignGauge)
Expand Down Expand Up @@ -209,6 +215,7 @@ func NewManager(logger zerolog.Logger, config configPkg.MetricsConfig) *Manager
reconnectsCounter: reconnectsCounter,
missingBlocksGauge: missingBlocksGauge,
activeBlocksGauge: activeBlocksGauge,
votingPowerGauge: votingPowerGauge,
isActiveGauge: isActiveGauge,
isJailedGauge: isJailedGauge,
needsToSignGauge: needsToSignGauge,
Expand Down Expand Up @@ -406,14 +413,24 @@ func (m *Manager) LogValidatorStats(
Set(utils.BoolToFloat64(validator.SigningInfo.Tombstoned))
}

if chain.IsConsumer.Bool && validator.Active() {
m.needsToSignGauge.
if validator.Active() {
if chain.IsConsumer.Bool {
m.needsToSignGauge.
With(prometheus.Labels{
"chain": chain.Name,
"moniker": validator.Moniker,
"address": validator.OperatorAddress,
}).
Set(utils.BoolToFloat64(validator.NeedsToSign))

Check warning on line 424 in pkg/metrics/metrics.go

View check run for this annotation

Codecov / codecov/patch

pkg/metrics/metrics.go#L417-L424

Added lines #L417 - L424 were not covered by tests
}

m.votingPowerGauge.
With(prometheus.Labels{
"chain": chain.Name,
"moniker": validator.Moniker,
"address": validator.OperatorAddress,
}).
Set(utils.BoolToFloat64(validator.NeedsToSign))
Set(validator.VotingPowerPercent)

Check warning on line 433 in pkg/metrics/metrics.go

View check run for this annotation

Codecov / codecov/patch

pkg/metrics/metrics.go#L427-L433

Added lines #L427 - L433 were not covered by tests
}
}

Expand Down

0 comments on commit 905db65

Please sign in to comment.