-
Notifications
You must be signed in to change notification settings - Fork 18
/
gauges.go
39 lines (33 loc) · 986 Bytes
/
gauges.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
package system
import (
"context"
"fmt"
"strings"
"github.com/circleci/ex/o11y"
)
type GaugeProducer interface {
// GaugeName The name for this group of metrics
//(Name might be cleaner, but is much more likely to conflict in implementations)
GaugeName() string
// Gauges are instantaneous name value pairs
Gauges(context.Context) map[string][]TaggedValue
}
type TaggedValue struct {
Val float64
Tags []string
}
func emitGauges(ctx context.Context, producers []GaugeProducer) {
metrics := o11y.FromContext(ctx).MetricsProvider()
for _, producer := range producers {
emitGauge(ctx, metrics, producer)
}
}
func emitGauge(ctx context.Context, provider o11y.MetricsProvider, producer GaugeProducer) {
producerName := strings.Replace(producer.GaugeName(), "-", "_", -1)
for f, tvs := range producer.Gauges(ctx) {
for _, tv := range tvs {
scopedField := fmt.Sprintf("gauge.%s.%s", producerName, f)
_ = provider.Gauge(scopedField, tv.Val, tv.Tags, 1)
}
}
}