forked from go-kit/kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
multi.go
73 lines (60 loc) · 1.51 KB
/
multi.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package metrics
type multiCounter []Counter
// NewMultiCounter returns a wrapper around multiple Counters.
func NewMultiCounter(counters ...Counter) Counter {
c := make(multiCounter, 0, len(counters))
return append(c, counters...)
}
func (c multiCounter) With(f Field) Counter {
next := make(multiCounter, len(c))
for i, counter := range c {
next[i] = counter.With(f)
}
return next
}
func (c multiCounter) Add(delta uint64) {
for _, counter := range c {
counter.Add(delta)
}
}
type multiGauge []Gauge
// NewMultiGauge returns a wrapper around multiple Gauges.
func NewMultiGauge(gauges ...Gauge) Gauge {
g := make(multiGauge, 0, len(gauges))
return append(g, gauges...)
}
func (g multiGauge) With(f Field) Gauge {
next := make(multiGauge, len(g))
for i, gauge := range g {
next[i] = gauge.With(f)
}
return next
}
func (g multiGauge) Set(value float64) {
for _, gauge := range g {
gauge.Set(value)
}
}
func (g multiGauge) Add(delta float64) {
for _, gauge := range g {
gauge.Add(delta)
}
}
type multiHistogram []Histogram
// NewMultiHistogram returns a wrapper around multiple Histograms.
func NewMultiHistogram(histograms ...Histogram) Histogram {
h := make(multiHistogram, 0, len(histograms))
return append(h, histograms...)
}
func (h multiHistogram) With(f Field) Histogram {
next := make(multiHistogram, len(h))
for i, histogram := range h {
next[i] = histogram.With(f)
}
return next
}
func (h multiHistogram) Observe(value int64) {
for _, histogram := range h {
histogram.Observe(value)
}
}