forked from traefik/traefik
-
Notifications
You must be signed in to change notification settings - Fork 0
/
metrics.go
57 lines (46 loc) · 1.75 KB
/
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
46
47
48
49
50
51
52
53
54
55
56
57
package testhelpers
import "github.com/go-kit/kit/metrics"
// CollectingCounter is a metrics.Counter implementation that enables access to the CounterValue and LastLabelValues.
type CollectingCounter struct {
CounterValue float64
LastLabelValues []string
}
// With is there to satisfy the metrics.Counter interface.
func (c *CollectingCounter) With(labelValues ...string) metrics.Counter {
c.LastLabelValues = labelValues
return c
}
// Add is there to satisfy the metrics.Counter interface.
func (c *CollectingCounter) Add(delta float64) {
c.CounterValue += delta
}
// CollectingGauge is a metrics.Gauge implementation that enables access to the GaugeValue and LastLabelValues.
type CollectingGauge struct {
GaugeValue float64
LastLabelValues []string
}
// With is there to satisfy the metrics.Gauge interface.
func (g *CollectingGauge) With(labelValues ...string) metrics.Gauge {
g.LastLabelValues = labelValues
return g
}
// Set is there to satisfy the metrics.Gauge interface.
func (g *CollectingGauge) Set(value float64) {
g.GaugeValue = value
}
// Add is there to satisfy the metrics.Gauge interface.
func (g *CollectingGauge) Add(delta float64) {
g.GaugeValue = delta
}
// CollectingHealthCheckMetrics can be used for testing the Metrics instrumentation of the HealthCheck package.
type CollectingHealthCheckMetrics struct {
Gauge *CollectingGauge
}
// BackendServerUpGauge is there to satisfy the healthcheck.metricsRegistry interface.
func (m *CollectingHealthCheckMetrics) BackendServerUpGauge() metrics.Gauge {
return m.Gauge
}
// NewCollectingHealthCheckMetrics creates a new CollectingHealthCheckMetrics instance.
func NewCollectingHealthCheckMetrics() *CollectingHealthCheckMetrics {
return &CollectingHealthCheckMetrics{&CollectingGauge{}}
}