-
Notifications
You must be signed in to change notification settings - Fork 54
/
metrics.go
79 lines (71 loc) · 2.09 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package konfig
import "github.com/prometheus/client_golang/prometheus"
var (
// MetricsConfigReload is the label for the prometheus counter for loader reload
MetricsConfigReload = "konfig_loader_reload"
// MetricsConfigReloadDuration is the label for the prometheus summary vector for loader reload duration
MetricsConfigReloadDuration = "konfig_loader_reload_duration"
)
const (
metricsSuccessLabel = "success"
metricsFailureLabel = "failure"
)
// LoaderMetrics is the structure holding the promtheus metrics objects
type loaderMetrics struct {
configReloadSuccess prometheus.Counter
configReloadFailure prometheus.Counter
configReloadDuration prometheus.Observer
}
func (lw *loaderWatcher) setMetrics() {
var (
configReloadCounterVec = lw.s.metrics[MetricsConfigReload].(*prometheus.CounterVec)
configReloadDurationSummaryVec = lw.s.metrics[MetricsConfigReloadDuration].(*prometheus.SummaryVec)
)
lw.metrics = &loaderMetrics{
configReloadSuccess: configReloadCounterVec.
WithLabelValues(
metricsSuccessLabel,
lw.s.name,
lw.Name(),
),
configReloadFailure: configReloadCounterVec.
WithLabelValues(
metricsFailureLabel,
lw.s.name,
lw.Name(),
),
configReloadDuration: configReloadDurationSummaryVec.
WithLabelValues(
lw.s.name,
lw.Name(),
),
}
}
func (c *S) initMetrics() {
c.metrics = map[string]prometheus.Collector{
MetricsConfigReload: prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: MetricsConfigReload,
Help: "Number of config loader reload",
},
[]string{"result", "store", "loader"},
),
MetricsConfigReloadDuration: prometheus.NewSummaryVec(
prometheus.SummaryOpts{
Name: MetricsConfigReloadDuration,
Help: "Histogram for the config reload duration",
Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001},
},
[]string{"store", "loader"},
),
}
}
func (c *S) registerMetrics() error {
for _, metric := range c.metrics {
var err = prometheus.Register(metric)
if err != nil && err != err.(prometheus.AlreadyRegisteredError) {
return err
}
}
return nil
}