forked from 0xPolygonHermez/cdk-erigon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetrics.go
35 lines (31 loc) · 769 Bytes
/
metrics.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package sync_stages
import (
"fmt"
"github.com/VictoriaMetrics/metrics"
"github.com/huandu/xstrings"
"github.com/ledgerwatch/erigon-lib/kv"
)
var Metrics = map[SyncStage]*metrics.Counter{}
// TODO: this needs improving to support passing in different sets of stages
func init() {
for _, v := range AllStages {
Metrics[v] = metrics.GetOrCreateCounter(
fmt.Sprintf(
`sync{stage="%s"}`,
xstrings.ToSnakeCase(string(v)),
),
)
}
}
// UpdateMetrics - need update metrics manually because current "metrics" package doesn't support labels
// need to fix it in future
func UpdateMetrics(tx kv.Tx) error {
for id, m := range Metrics {
progress, err := GetStageProgress(tx, id)
if err != nil {
return err
}
m.Set(progress)
}
return nil
}