From dfd575df4f5117c600e078aa3592af1408a48ec9 Mon Sep 17 00:00:00 2001 From: Alexgao001 Date: Thu, 12 Oct 2023 17:54:34 +0800 Subject: [PATCH] show balance metric --- executor/bsc_executor.go | 5 ++--- executor/const.go | 1 + metric/service.go | 16 ++++++---------- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/executor/bsc_executor.go b/executor/bsc_executor.go index 2dcfe33..0710654 100644 --- a/executor/bsc_executor.go +++ b/executor/bsc_executor.go @@ -571,21 +571,20 @@ func (e *BSCExecutor) ClaimRewardLoop() { continue } logging.Logger.Infof("current relayer balance is %v", balance) + balance.Div(balance, BSCBalanceThreshold) + e.metricService.SetBSCBalance(float64(balance.Int64())) // should not claim if balance > 1 BNB if balance.Cmp(BSCBalanceThreshold) > 0 { - e.metricService.SetBSCLowBalance(false) continue } rewardBalance, err := e.getRewardBalance() if err != nil { - e.metricService.SetBSCLowBalance(true) logging.Logger.Errorf("failed to get relayer reward balance err=%s", err.Error()) continue } logging.Logger.Infof("current relayer reward balance is %v", balance) if rewardBalance.Cmp(BSCRewardThreshold) <= 0 { - e.metricService.SetBSCLowBalance(true) continue } // > 0.1 BNB diff --git a/executor/const.go b/executor/const.go index a38c25b..7f9632f 100644 --- a/executor/const.go +++ b/executor/const.go @@ -19,4 +19,5 @@ const ( var ( BSCBalanceThreshold = big.NewInt(1000000000000000000) // when relayer is lower than 1BNB, it should try to claim rewards BSCRewardThreshold = big.NewInt(100000000000000000) // if reward is lower than 0.1 BNB, it will not be claimed. + ) diff --git a/metric/service.go b/metric/service.go index 87e8a94..43e01dc 100644 --- a/metric/service.go +++ b/metric/service.go @@ -27,7 +27,7 @@ const ( MetricNameNextSendSequenceForChannel = "next_send_seq_for_channel" MetricNameNextReceiveSequenceForChannel = "next_receive_seq_for_channel" - MetricNameBSCLowBalance = "bsc_low_balance" + MetricNameBSCBalance = "bsc_balance" MetricNameHasTxDelay = "tx_delay" ) @@ -165,10 +165,10 @@ func NewMetricService(config *config.Config) *MetricService { } bscLowBalanceMetric := prometheus.NewGauge(prometheus.GaugeOpts{ - Name: MetricNameBSCLowBalance, - Help: "BSC relayer balance is lower than 1BNB, and not enoght reward(<0.1BNB)", + Name: MetricNameBSCBalance, + Help: "BSC relayer balance", }) - ms[MetricNameBSCLowBalance] = bscLowBalanceMetric + ms[MetricNameBSCBalance] = bscLowBalanceMetric prometheus.MustRegister(bscLowBalanceMetric) hasTxDelayMetric := prometheus.NewGauge(prometheus.GaugeOpts{ @@ -260,12 +260,8 @@ func (m *MetricService) SetNextReceiveSequenceForChannel(channel uint8, seq uint m.MetricsMap[fmt.Sprintf("%s_%d", MetricNameNextReceiveSequenceForChannel, channel)].(prometheus.Gauge).Set(float64(seq)) } -func (m *MetricService) SetBSCLowBalance(isLow bool) { - var flag float64 - if isLow { - flag = 1 - } - m.MetricsMap[MetricNameBSCLowBalance].(prometheus.Gauge).Set(flag) +func (m *MetricService) SetBSCBalance(balance float64) { + m.MetricsMap[MetricNameBSCBalance].(prometheus.Gauge).Set(balance) } func (m *MetricService) SetHasTxDelay(hasDelay bool) {