1 // Package multi provides adapters that send observations to multiple metrics
2 // simultaneously. This is useful if your service needs to emit to multiple
3 // instrumentation systems at the same time, for example if your organization is
4 // transitioning from one system to another.
7 import "github.com/go-kit/kit/metrics"
9 // Counter collects multiple individual counters and treats them as a unit.
10 type Counter []metrics.Counter
12 // NewCounter returns a multi-counter, wrapping the passed counters.
13 func NewCounter(c ...metrics.Counter) Counter {
17 // Add implements counter.
18 func (c Counter) Add(delta float64) {
19 for _, counter := range c {
24 // With implements counter.
25 func (c Counter) With(labelValues ...string) metrics.Counter {
26 next := make(Counter, len(c))
28 next[i] = c[i].With(labelValues...)
33 // Gauge collects multiple individual gauges and treats them as a unit.
34 type Gauge []metrics.Gauge
36 // NewGauge returns a multi-gauge, wrapping the passed gauges.
37 func NewGauge(g ...metrics.Gauge) Gauge {
41 // Set implements Gauge.
42 func (g Gauge) Set(value float64) {
43 for _, gauge := range g {
48 // With implements gauge.
49 func (g Gauge) With(labelValues ...string) metrics.Gauge {
50 next := make(Gauge, len(g))
52 next[i] = g[i].With(labelValues...)
57 // Add implements metrics.Gauge.
58 func (g Gauge) Add(delta float64) {
59 for _, gauge := range g {
64 // Histogram collects multiple individual histograms and treats them as a unit.
65 type Histogram []metrics.Histogram
67 // NewHistogram returns a multi-histogram, wrapping the passed histograms.
68 func NewHistogram(h ...metrics.Histogram) Histogram {
72 // Observe implements Histogram.
73 func (h Histogram) Observe(value float64) {
74 for _, histogram := range h {
75 histogram.Observe(value)
79 // With implements histogram.
80 func (h Histogram) With(labelValues ...string) metrics.Histogram {
81 next := make(Histogram, len(h))
83 next[i] = h[i].With(labelValues...)