/
metrics.go
70 lines (60 loc) · 2.15 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
package customeradmin
import (
"net/http"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
var (
azureControllersRegistry = prometheus.NewRegistry()
// TODO(charlesakalugwu): Add unit tests for the handling of these metrics once
// the upstream library supports it
azureControllersErrorsCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "azure_controllers_errors_total",
Help: "Total number of errors.",
},
[]string{"controller"},
)
azureControllersInFlightGauge = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "azure_controllers_reconciliations_inflight",
Help: "Number of azure controller reconciliations in progress.",
},
[]string{"controller"},
)
azureControllersLastExecutedGauge = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "azure_controllers_last_executed",
Help: "The last time the azure controllers were run.",
},
[]string{"controller"},
)
azureControllersDurationSummary = prometheus.NewSummaryVec(
prometheus.SummaryOpts{
Name: "azure_controllers_duration_seconds",
Help: "The duration of azure controller runs.",
},
[]string{"controller"},
)
)
func init() {
azureControllersRegistry.MustRegister(
prometheus.NewGoCollector(),
prometheus.NewProcessCollector(prometheus.ProcessCollectorOpts{}),
)
azureControllersRegistry.MustRegister(azureControllersErrorsCounter)
azureControllersRegistry.MustRegister(azureControllersInFlightGauge)
azureControllersRegistry.MustRegister(azureControllersLastExecutedGauge)
azureControllersRegistry.MustRegister(azureControllersDurationSummary)
// initialize metrics with known label values to 0 otherwise their time series
// will be missing until they are used
for _, controller := range knownControllers {
azureControllersErrorsCounter.WithLabelValues(controller)
azureControllersInFlightGauge.WithLabelValues(controller)
azureControllersLastExecutedGauge.WithLabelValues(controller)
azureControllersDurationSummary.WithLabelValues(controller)
}
}
func MetricsHandler() http.Handler {
return promhttp.HandlerFor(azureControllersRegistry, promhttp.HandlerOpts{})
}