-
Notifications
You must be signed in to change notification settings - Fork 921
/
metrics.go
45 lines (37 loc) · 880 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
36
37
38
39
40
41
42
43
44
45
package sync
import (
"context"
"sync/atomic"
"go.opentelemetry.io/otel/metric/global"
"go.opentelemetry.io/otel/metric/instrument"
)
var meter = global.MeterProvider().Meter("header/sync")
type metrics struct {
totalSynced int64
}
func (s *Syncer[H]) InitMetrics() error {
s.metrics = &metrics{}
totalSynced, err := meter.
AsyncFloat64().
Gauge(
"total_synced_headers",
instrument.WithDescription("total synced headers"),
)
if err != nil {
return err
}
return meter.RegisterCallback(
[]instrument.Asynchronous{
totalSynced,
},
func(ctx context.Context) {
totalSynced.Observe(ctx, float64(atomic.LoadInt64(&s.metrics.totalSynced)))
},
)
}
// recordTotalSynced records the total amount of synced headers.
func (m *metrics) recordTotalSynced(totalSynced int) {
if m != nil {
atomic.AddInt64(&m.totalSynced, int64(totalSynced))
}
}