Skip to content

Commit

Permalink
Merge pull request #3 from axieinfinity/bugfix/metrics
Browse files Browse the repository at this point in the history
Bugfix/metrics
  • Loading branch information
ssscrom authored Aug 23, 2022
2 parents be16481 + 21d7c22 commit c7ef342
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 27 deletions.
64 changes: 58 additions & 6 deletions adapters/prometheus/pusher.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/axieinfinity/bridge-core/adapters"

"github.com/ethereum/go-ethereum/log"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/push"
)
Expand All @@ -32,6 +33,21 @@ func (p *Pusher) AddCounter(name string, description string) *Pusher {
return p
}

func (p *Pusher) AddCounterWithLable(name string, description string, labels map[string]string) *Pusher {
if _, ok := p.counters[name]; ok {
return p
}

counter := prometheus.NewCounter(prometheus.CounterOpts{
Name: name,
Help: description,
ConstLabels: labels,
})
p.counters[name] = counter
p.pusher.Collector(counter)
return p
}

func (p *Pusher) IncrCounter(name string, value int) {
if _, ok := p.counters[name]; !ok {
return
Expand All @@ -43,11 +59,25 @@ func (p *Pusher) AddGauge(name string, description string) *Pusher {
if _, ok := p.gauges[name]; ok {
return p
}

gauge := prometheus.NewGauge(prometheus.GaugeOpts{
Name: name,
Help: description,
})
p.gauges[name] = gauge
p.pusher.Collector(gauge)
return p
}

func (p *Pusher) AddGaugeWithLabel(name string, description string, labels map[string]string) *Pusher {
if _, ok := p.gauges[name]; ok {
return p
}
gauge := prometheus.NewGauge(prometheus.GaugeOpts{
Name: name,
Help: description,
ConstLabels: labels,
})
p.gauges[name] = gauge
p.pusher.Collector(gauge)
return p
}
Expand Down Expand Up @@ -77,6 +107,22 @@ func (p *Pusher) AddHistogram(name string, description string) *Pusher {
Name: name,
Help: description,
})
p.histograms[name] = histogram
p.pusher.Collector(histogram)
return p
}

func (p *Pusher) AddHistogramWithLabels(name string, description string, labels map[string]string) *Pusher {
if _, ok := p.histograms[name]; ok {
return p
}

histogram := prometheus.NewHistogram(prometheus.HistogramOpts{
Name: name,
Help: description,
ConstLabels: labels,
})
p.histograms[name] = histogram
p.pusher.Collector(histogram)
return p
}
Expand All @@ -95,12 +141,18 @@ func (p *Pusher) Push() error {

func (p *Pusher) Start(ctx context.Context) {
ticker := time.NewTicker(time.Second * time.Duration(adapters.AppConfig.Prometheus.PushInterval))
select {
case <-ticker.C:
p.pusher.Push()
case <-ctx.Done():
ticker.Stop()
for {
select {
case <-ticker.C:
if err := p.Push(); err != nil {
log.Error("Push metrics got error", err)
}
case <-ctx.Done():
ticker.Stop()
return
}
}

}

func NewPusher() *Pusher {
Expand Down
42 changes: 21 additions & 21 deletions metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@ import (
)

const (
ListenerProcessedBlockMetric string = "%s/processedBlock"

PreparingFailedJobMetric string = "jobs/prepare/failed"
PreparingSuccessJobMetric string = "jobs/prepare/success"
ProcessingJobMetric string = "jobs/processing"
ProcessedSuccessJobMetric string = "jobs/success"
ProcessedFailedJobMetric string = "jobs/failed"

PendingTaskMetric string = "Ronin/tasks/pending"
ProcessingTaskMetric string = "Ronin/tasks/processing"
SuccessTaskMetric string = "Ronin/tasks/success"
FailedTaskMetric string = "Ronin/tasks/failed"
WithdrawalTaskMetric string = "Ronin/tasks/withdrawal"
DepositTaskMetric string = "Ronin/tasks/deposit"
AckWithdrawalTaskMetric string = "Ronin/tasks/acknowledgeWithdrawal"

KmsSuccessSign string = "kms/success"
KmsNetworkFailure string = "kms/failure/network"
KmsInternalFailure string = "kms/failure/internal"
KmsSignLatency string = "kms/latency"
KmsLastSuccess string = "kms/lastSuccess"
ListenerProcessedBlockMetric string = "%s_processedBlock"

PreparingFailedJobMetric string = "jobs_prepare_failed"
PreparingSuccessJobMetric string = "jobs_prepare_success"
ProcessingJobMetric string = "jobs_processing"
ProcessedSuccessJobMetric string = "jobs_success"
ProcessedFailedJobMetric string = "jobs_failed"

PendingTaskMetric string = "Ronin_tasks_pending"
ProcessingTaskMetric string = "Ronin_tasks_processing"
SuccessTaskMetric string = "Ronin_tasks_success"
FailedTaskMetric string = "Ronin_tasks_failed"
WithdrawalTaskMetric string = "Ronin_tasks_withdrawal"
DepositTaskMetric string = "Ronin_tasks_deposit"
AckWithdrawalTaskMetric string = "Ronin_tasks_acknowledgeWithdrawal"

KmsSuccessSign string = "kms_success"
KmsNetworkFailure string = "kms_failure/network"
KmsInternalFailure string = "kms_failure/internal"
KmsSignLatency string = "kms_latency"
KmsLastSuccess string = "kms_lastSuccess"
)

var (
Expand Down

0 comments on commit c7ef342

Please sign in to comment.