From 8bb260bc1b6629de67c62dfa3a2120c968f2bc4f Mon Sep 17 00:00:00 2001 From: batphonghan Date: Fri, 19 Jan 2024 09:09:51 +0700 Subject: [PATCH] Add more metrics --- shared/services/state/network-state.go | 18 ++++++++++++++++++ stader/guardian/collector/constants.go | 2 ++ .../guardian/collector/operator-collector.go | 10 ++++++++++ stader/guardian/collector/state-locker.go | 1 + 4 files changed, 31 insertions(+) diff --git a/shared/services/state/network-state.go b/shared/services/state/network-state.go index 3ad016b69..e62d89689 100644 --- a/shared/services/state/network-state.go +++ b/shared/services/state/network-state.go @@ -138,6 +138,11 @@ type MetricDetails struct { // done HealthFactor float64 + + // done + LiquidationStatus float64 + + ClaimVaultBalance float64 } type MetricsCache struct { @@ -506,6 +511,16 @@ func CreateMetricsCache( return nil, err } + orc, err := services.GetOperatorRewardsCollectorContract(c) + if err != nil { + return nil, err + } + + operatorClaimVaultBalance, err := node.GetOperatorRewardsCollectorBalance(orc, nodeAddress, nil) + if err != nil { + return nil, err + } + minThreshold := math.RoundDown(eth.WeiToEth(permissionlessPoolThreshold.MinThreshold), 2) sdPriceFormatted := math.RoundDown(eth.WeiToEth(sdPrice), 2) collateralRatioInSd := minThreshold * sdPriceFormatted @@ -581,6 +596,9 @@ func CreateMetricsCache( metricsDetails.OperatorSDSelfBond = math.RoundDown(eth.WeiToEth(operatorSdCollateral), SixDecimalRound) + metricsDetails.LiquidationStatus = 0 + metricsDetails.ClaimVaultBalance = math.RoundDown(eth.WeiToEth(operatorClaimVaultBalance), SixDecimalRound) + state.StaderNetworkDetails = metricsDetails state.logLine("Retrieved Stader Network Details (total time: %s)", time.Since(start)) diff --git a/stader/guardian/collector/constants.go b/stader/guardian/collector/constants.go index 3a27be0b7..43d1b9f5b 100644 --- a/stader/guardian/collector/constants.go +++ b/stader/guardian/collector/constants.go @@ -36,6 +36,8 @@ const LockedEth = "eth_locked" const HeathFactor = "heath_factor" const TotalSDUtilizationPosition = "sd_utility_position" const TotalSDSelfBonded = "total_sd_self_bonded" +const LiquidationStatus = "liquidation_status" +const ClaimVaultBalance = "claim_vault_balance" // Node Health => stader_node_health+ key const NodeSub = "node_health" diff --git a/stader/guardian/collector/operator-collector.go b/stader/guardian/collector/operator-collector.go index 4269d9265..366098214 100644 --- a/stader/guardian/collector/operator-collector.go +++ b/stader/guardian/collector/operator-collector.go @@ -40,6 +40,8 @@ type OperatorCollector struct { SdCollateralPct *prometheus.Desc LockedEth *prometheus.Desc HealthFactor *prometheus.Desc + LiquidationStatus *prometheus.Desc + ClaimVaultBalance *prometheus.Desc // The beacon client bc beacon.Client @@ -133,6 +135,10 @@ func NewOperatorCollector( prometheus.BuildFQName(namespace, OperatorSub, TotalSDUtilizationPosition), "", nil, nil), TotalSDSelfBond: prometheus.NewDesc( prometheus.BuildFQName(namespace, OperatorSub, TotalSDSelfBonded), "", nil, nil), + LiquidationStatus: prometheus.NewDesc( + prometheus.BuildFQName(namespace, OperatorSub, LiquidationStatus), "", nil, nil), + ClaimVaultBalance: prometheus.NewDesc( + prometheus.BuildFQName(namespace, OperatorSub, ClaimVaultBalance), "", nil, nil), bc: bc, ec: ec, nodeAddress: nodeAddress, @@ -170,6 +176,8 @@ func (collector *OperatorCollector) Describe(channel chan<- *prometheus.Desc) { channel <- collector.HealthFactor channel <- collector.TotalSDUtilizationPosition channel <- collector.TotalSDSelfBond + channel <- collector.LiquidationStatus + channel <- collector.ClaimVaultBalance } // Collect the latest metric values and pass them to Prometheus @@ -204,6 +212,8 @@ func (collector *OperatorCollector) Collect(channel chan<- prometheus.Metric) { channel <- prometheus.MustNewConstMetric(collector.HealthFactor, prometheus.GaugeValue, state.StaderNetworkDetails.HealthFactor) channel <- prometheus.MustNewConstMetric(collector.TotalSDUtilizationPosition, prometheus.GaugeValue, float64(state.StaderNetworkDetails.OperatorSDUtilizationPosition)) channel <- prometheus.MustNewConstMetric(collector.TotalSDSelfBond, prometheus.GaugeValue, float64(state.StaderNetworkDetails.OperatorSDSelfBond)) + channel <- prometheus.MustNewConstMetric(collector.LiquidationStatus, prometheus.GaugeValue, state.StaderNetworkDetails.LiquidationStatus) + channel <- prometheus.MustNewConstMetric(collector.ClaimVaultBalance, prometheus.GaugeValue, state.StaderNetworkDetails.ClaimVaultBalance) } // Log error messages diff --git a/stader/guardian/collector/state-locker.go b/stader/guardian/collector/state-locker.go index 3cdc08791..dd690bb18 100644 --- a/stader/guardian/collector/state-locker.go +++ b/stader/guardian/collector/state-locker.go @@ -66,6 +66,7 @@ func NewMetricsCacheContainer() *MetricsCacheContainer { SdCollateralPct: 0, LockedEth: 0, HealthFactor: 0, + LiquidationStatus: 0, StaderQueuedValidators: big.NewInt(0), }, },