Skip to content

Commit

Permalink
Add more metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
batphonghan committed Jan 19, 2024
1 parent b79a0ef commit 8bb260b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
18 changes: 18 additions & 0 deletions shared/services/state/network-state.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ type MetricDetails struct {

// done
HealthFactor float64

// done
LiquidationStatus float64

ClaimVaultBalance float64
}

type MetricsCache struct {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down
2 changes: 2 additions & 0 deletions stader/guardian/collector/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 10 additions & 0 deletions stader/guardian/collector/operator-collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions stader/guardian/collector/state-locker.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func NewMetricsCacheContainer() *MetricsCacheContainer {
SdCollateralPct: 0,
LockedEth: 0,
HealthFactor: 0,
LiquidationStatus: 0,
StaderQueuedValidators: big.NewInt(0),
},
},
Expand Down

0 comments on commit 8bb260b

Please sign in to comment.