Skip to content

Commit

Permalink
feat: enhance validator metrics to include validator names for better…
Browse files Browse the repository at this point in the history
… tracking
  • Loading branch information
kalpins committed Oct 16, 2024
1 parent eb7f4cf commit 0b045eb
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 52 deletions.
54 changes: 27 additions & 27 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,215 +261,215 @@ func New(namespace string) *Metrics {
Name: "validator_balance_available",
Help: "Validator balance available",
},
[]string{"address"},
[]string{"address", "name"},
),
ValidatorCommission: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "validator_balance_commission",
Help: "Validator commission",
},
[]string{"address"},
[]string{"address", "name"},
),
ValidatorBalanceDelegated: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "validator_balance_delegated",
Help: "Validator balance delegated",
},
[]string{"address"},
[]string{"address", "name"},
),
ValidatorBalanceReward: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "validator_balance_reward",
Help: "Validator balance reward",
},
[]string{"address"},
[]string{"address", "name"},
),
ValidatorBalanceUnBonding: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "validator_balance_unbonding",
Help: "Validator balance unbonding",
},
[]string{"address"},
[]string{"address", "name"},
),
ValidatorDelegators: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "validator_delegators",
Help: "Validator delegators",
},
[]string{"address"},
[]string{"address", "name"},
),
ValidatorStatus: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "validator_status",
Help: "Validator status",
},
[]string{"address"},
[]string{"address", "name"},
),
ValidatorTokens: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "validator_tokens",
Help: "Validator tokens",
},
[]string{"address"},
[]string{"address", "name"},
),
ValidatorCommissionRate: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "validator_commission_rate",
Help: "Validator commission rate",
},
[]string{"address"},
[]string{"address", "name"},
),
ValidatorDelegatorShares: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "validator_delegator_shares",
Help: "Validator delegator shares",
},
[]string{"address"},
[]string{"address", "name"},
),
ValidatorUnbondingTime: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "validator_unbonding_time",
Help: "Validator unbonding time",
},
[]string{"address"},
[]string{"address", "name"},
),
ValidatorMinSelfDelegation: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "validator_min_self_delegation",
Help: "Validator min self delegation",
},
[]string{"address"},
[]string{"address", "name"},
),
ValidatorParticipationRate: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "validator_participation_rate",
Help: "Validator participation rate",
},
[]string{"address"},
[]string{"address", "name"},
),
ValidatorParticipationTotal: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "validator_participation_total",
Help: "Validator participation total",
},
[]string{"address"},
[]string{"address", "name"},
),
ValidatorSigningInfo: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "validator_signing_info",
Help: "Validator signing info",
},
[]string{"address"},
[]string{"address", "name"},
),
ValidatorUptime: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "validator_uptime",
Help: "Validator uptime",
},
[]string{"address"},
[]string{"address", "name"},
),
ValidatorVotingPowerPercent: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "validator_voting_power_percent",
Help: "Validator voting power percent",
},
[]string{"address"},
[]string{"address", "name"},
),
ValidatorCumulativeShare: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "validator_cumulative_share",
Help: "Validator cumulative share",
},
[]string{"address"},
[]string{"address", "name"},
),
ValidatorParticipationVoted: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "validator_participation_voted",
Help: "Validator participation voted",
},
[]string{"address"},
[]string{"address", "name"},
),
ValidatorSigningInfoBondedHeight: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "validator_signing_info_bonded_height",
Help: "Validator signing info bonded height",
},
[]string{"address"},
[]string{"address", "name"},
),
ValidatorSigningInfoTombstoned: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "validator_signing_info_tombstoned",
Help: "Validator signing info tombstoned",
},
[]string{"address"},
[]string{"address", "name"},
),
ValidatorUptimeHistoricalEarliestHeight: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "validator_uptime_historical_earliest_height",
Help: "Validator uptime historical earliest height",
},
[]string{"address"},
[]string{"address", "name"},
),
ValidatorUptimeHistoricalLastSyncHeight: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "validator_uptime_historical_last_sync_height",
Help: "Validator uptime historical last sync height",
},
[]string{"address"},
[]string{"address", "name"},
),
ValidatorUptimeHistoricalSuccessBlocks: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "validator_uptime_historical_success_blocks",
Help: "Validator uptime historical success blocks",
},
[]string{"address"},
[]string{"address", "name"},
),
ValidatorUptimeWindowUptime: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "validator_uptime_window_uptime",
Help: "Validator uptime window uptime",
},
[]string{"address"},
[]string{"address", "name"},
),
ValidatorUptimeWindowStart: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "validator_uptime_window_start",
Help: "Validator uptime window start",
},
[]string{"address"},
[]string{"address", "name"},
),
ValidatorUptimeWindowEnd: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "validator_uptime_window_end",
Help: "Validator uptime window end",
},
[]string{"address"},
[]string{"address", "name"},
),
}

Expand Down
50 changes: 25 additions & 25 deletions pkg/watcher/validators_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,11 @@ func (w *ValidatorsAPIWatcher) fetchAccount(ctx context.Context, validator Track
log.Debug().Interface("account", account).Str("validator", validator.Account).Msg("fetched account info")

// update metrics
w.metrics.ValidatorBalanceAvailable.WithLabelValues(validator.Address).Set(float64(account.Balance.Available))
w.metrics.ValidatorCommission.WithLabelValues(validator.Address).Set(float64(account.Balance.Commission))
w.metrics.ValidatorBalanceDelegated.WithLabelValues(validator.Address).Set(float64(account.Balance.Delegated))
w.metrics.ValidatorBalanceReward.WithLabelValues(validator.Address).Set(float64(account.Balance.Reward))
w.metrics.ValidatorBalanceUnBonding.WithLabelValues(validator.Address).Set(float64(account.Balance.Unbonding))
w.metrics.ValidatorBalanceAvailable.WithLabelValues(validator.Address, validator.Name).Set(float64(account.Balance.Available))
w.metrics.ValidatorCommission.WithLabelValues(validator.Address, validator.Name).Set(float64(account.Balance.Commission))
w.metrics.ValidatorBalanceDelegated.WithLabelValues(validator.Address, validator.Name).Set(float64(account.Balance.Delegated))
w.metrics.ValidatorBalanceReward.WithLabelValues(validator.Address, validator.Name).Set(float64(account.Balance.Reward))
w.metrics.ValidatorBalanceUnBonding.WithLabelValues(validator.Address, validator.Name).Set(float64(account.Balance.Unbonding))

return nil
}
Expand Down Expand Up @@ -218,25 +218,25 @@ func (w *ValidatorsAPIWatcher) fetchValidator(ctx context.Context, validator Tra
log.Debug().Interface("validator", apiValidator).Str("validator", validator.Account).Msg("fetched validator info")

// update metrics
w.metrics.ValidatorStatus.WithLabelValues(validator.Address).Set(float64(apiValidator.Status))
w.metrics.ValidatorTokens.WithLabelValues(validator.Address).Set(float64(apiValidator.Tokens))
w.metrics.ValidatorCommissionRate.WithLabelValues(validator.Address).Set(MustFloat64(apiValidator.Commission.CommissionRates.Rate))
w.metrics.ValidatorDelegatorShares.WithLabelValues(validator.Address).Set(MustFloat64(apiValidator.DelegatorShares))
w.metrics.ValidatorUnbondingTime.WithLabelValues(validator.Address).Set(float64(apiValidator.UnbondingTime.Unix()))
w.metrics.ValidatorMinSelfDelegation.WithLabelValues(validator.Address).Set(MustFloat64(apiValidator.MinSelfDelegation))
w.metrics.ValidatorParticipationRate.WithLabelValues(validator.Address).Set(float64(apiValidator.Participation.Rate))
w.metrics.ValidatorParticipationTotal.WithLabelValues(validator.Address).Set(float64(apiValidator.Participation.Total))
w.metrics.ValidatorParticipationVoted.WithLabelValues(validator.Address).Set(float64(apiValidator.Participation.Voted))
w.metrics.ValidatorSigningInfoBondedHeight.WithLabelValues(validator.Address).Set(float64(apiValidator.SigningInfo.BondedHeight))
w.metrics.ValidatorSigningInfoTombstoned.WithLabelValues(validator.Address).Set(metrics.BoolToFloat64(apiValidator.SigningInfo.Tombstoned))
w.metrics.ValidatorUptimeHistoricalEarliestHeight.WithLabelValues(validator.Address).Set(float64(apiValidator.Uptime.HistoricalUptime.EarliestHeight))
w.metrics.ValidatorUptimeHistoricalLastSyncHeight.WithLabelValues(validator.Address).Set(float64(apiValidator.Uptime.HistoricalUptime.LastSyncHeight))
w.metrics.ValidatorUptimeHistoricalSuccessBlocks.WithLabelValues(validator.Address).Set(float64(apiValidator.Uptime.HistoricalUptime.SuccessBlocks))
w.metrics.ValidatorUptimeWindowUptime.WithLabelValues(validator.Address).Set(apiValidator.Uptime.WindowUptime.Uptime)
w.metrics.ValidatorUptimeWindowStart.WithLabelValues(validator.Address).Set(float64(apiValidator.Uptime.WindowUptime.WindowStart))
w.metrics.ValidatorUptimeWindowEnd.WithLabelValues(validator.Address).Set(float64(apiValidator.Uptime.WindowUptime.WindowEnd))
w.metrics.ValidatorVotingPowerPercent.WithLabelValues(validator.Address).Set(apiValidator.VotingPowerPercent)
w.metrics.ValidatorCumulativeShare.WithLabelValues(validator.Address).Set(apiValidator.CumulativeShare)
w.metrics.ValidatorStatus.WithLabelValues(validator.Address, validator.Name).Set(float64(apiValidator.Status))
w.metrics.ValidatorTokens.WithLabelValues(validator.Address, validator.Name).Set(float64(apiValidator.Tokens))
w.metrics.ValidatorCommissionRate.WithLabelValues(validator.Address, validator.Name).Set(MustFloat64(apiValidator.Commission.CommissionRates.Rate))
w.metrics.ValidatorDelegatorShares.WithLabelValues(validator.Address, validator.Name).Set(MustFloat64(apiValidator.DelegatorShares))
w.metrics.ValidatorUnbondingTime.WithLabelValues(validator.Address, validator.Name).Set(float64(apiValidator.UnbondingTime.Unix()))
w.metrics.ValidatorMinSelfDelegation.WithLabelValues(validator.Address, validator.Name).Set(MustFloat64(apiValidator.MinSelfDelegation))
w.metrics.ValidatorParticipationRate.WithLabelValues(validator.Address, validator.Name).Set(float64(apiValidator.Participation.Rate))
w.metrics.ValidatorParticipationTotal.WithLabelValues(validator.Address, validator.Name).Set(float64(apiValidator.Participation.Total))
w.metrics.ValidatorParticipationVoted.WithLabelValues(validator.Address, validator.Name).Set(float64(apiValidator.Participation.Voted))
w.metrics.ValidatorSigningInfoBondedHeight.WithLabelValues(validator.Address, validator.Name).Set(float64(apiValidator.SigningInfo.BondedHeight))
w.metrics.ValidatorSigningInfoTombstoned.WithLabelValues(validator.Address, validator.Name).Set(metrics.BoolToFloat64(apiValidator.SigningInfo.Tombstoned))
w.metrics.ValidatorUptimeHistoricalEarliestHeight.WithLabelValues(validator.Address, validator.Name).Set(float64(apiValidator.Uptime.HistoricalUptime.EarliestHeight))
w.metrics.ValidatorUptimeHistoricalLastSyncHeight.WithLabelValues(validator.Address, validator.Name).Set(float64(apiValidator.Uptime.HistoricalUptime.LastSyncHeight))
w.metrics.ValidatorUptimeHistoricalSuccessBlocks.WithLabelValues(validator.Address, validator.Name).Set(float64(apiValidator.Uptime.HistoricalUptime.SuccessBlocks))
w.metrics.ValidatorUptimeWindowUptime.WithLabelValues(validator.Address, validator.Name).Set(apiValidator.Uptime.WindowUptime.Uptime)
w.metrics.ValidatorUptimeWindowStart.WithLabelValues(validator.Address, validator.Name).Set(float64(apiValidator.Uptime.WindowUptime.WindowStart))
w.metrics.ValidatorUptimeWindowEnd.WithLabelValues(validator.Address, validator.Name).Set(float64(apiValidator.Uptime.WindowUptime.WindowEnd))
w.metrics.ValidatorVotingPowerPercent.WithLabelValues(validator.Address, validator.Name).Set(apiValidator.VotingPowerPercent)
w.metrics.ValidatorCumulativeShare.WithLabelValues(validator.Address, validator.Name).Set(apiValidator.CumulativeShare)

return nil
}
Expand Down Expand Up @@ -280,7 +280,7 @@ func (w *ValidatorsAPIWatcher) fetchDelegator(ctx context.Context, validator Tra
// log.Debug().Str("validator", validator.Account).Int("delegators", apiResponse.ValidatorDelegators).Msg("fetched delegator info")

// update metrics
w.metrics.ValidatorDelegators.WithLabelValues(validator.Address).Set(float64(apiResponse.ValidatorDelegators))
w.metrics.ValidatorDelegators.WithLabelValues(validator.Address, validator.Name).Set(float64(apiResponse.ValidatorDelegators))

return nil
}
Expand Down

0 comments on commit 0b045eb

Please sign in to comment.