Skip to content

Commit

Permalink
show balance metric
Browse files Browse the repository at this point in the history
  • Loading branch information
alexgao001 committed Oct 12, 2023
1 parent eaa6160 commit dfd575d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
5 changes: 2 additions & 3 deletions executor/bsc_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions executor/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.

)
16 changes: 6 additions & 10 deletions metric/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit dfd575d

Please sign in to comment.