forked from linkerd/linkerd2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetrics.go
169 lines (148 loc) · 4.45 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
package servicemirror
import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
logging "github.com/sirupsen/logrus"
)
const (
gatewayClusterName = "target_cluster_name"
eventTypeLabelName = "event_type"
probeSuccessfulLabel = "probe_successful"
)
// ProbeMetricVecs stores metrics about about gateways collected by probe
// workers.
type ProbeMetricVecs struct {
gatewayEnabled *prometheus.GaugeVec
alive *prometheus.GaugeVec
latency *prometheus.GaugeVec
latencies *prometheus.HistogramVec
enqueues *prometheus.CounterVec
dequeues *prometheus.CounterVec
probes *prometheus.CounterVec
}
// ProbeMetrics stores metrics about about a specific gateway collected by a
// probe worker.
type ProbeMetrics struct {
gatewayEnabled prometheus.Gauge
alive prometheus.Gauge
latency prometheus.Gauge
latencies prometheus.Observer
probes *prometheus.CounterVec
unregister func()
}
var endpointRepairCounter *prometheus.CounterVec
func init() {
endpointRepairCounter = promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "service_mirror_endpoint_repairs",
Help: "Increments when the service mirror controller attempts to repair mirror endpoints",
},
[]string{gatewayClusterName},
)
}
// NewProbeMetricVecs creates a new ProbeMetricVecs.
func NewProbeMetricVecs() ProbeMetricVecs {
labelNames := []string{gatewayClusterName}
probes := promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "gateway_probes",
Help: "A counter for the number of actual performed probes to a gateway",
},
[]string{gatewayClusterName, probeSuccessfulLabel},
)
enqueues := promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "probe_manager_event_enqueues",
Help: "A counter for the number of enqueued events to the probe manager",
},
[]string{eventTypeLabelName},
)
dequeues := promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "probe_manager_event_dequeues",
Help: "A counter for the number of dequeued events to the probe manager",
},
[]string{eventTypeLabelName},
)
alive := promauto.NewGaugeVec(
prometheus.GaugeOpts{
Name: "gateway_alive",
Help: "A gauge which is 1 if the gateway is alive and 0 if it is not.",
},
labelNames,
)
gatewayEnabled :=
promauto.NewGaugeVec(
prometheus.GaugeOpts{
Name: "gateway_enabled",
Help: "A gauge which is 1 if the gateway is enabled, and 0 if it is not",
},
labelNames,
)
latency := promauto.NewGaugeVec(
prometheus.GaugeOpts{
Name: "gateway_latency",
Help: "A gauge which is the latency of the last probe to the gateway.",
},
labelNames,
)
latencies := promauto.NewHistogramVec(
prometheus.HistogramOpts{
Name: "gateway_probe_latency_ms",
Help: "A histogram of latencies to a gateway in a target cluster.",
Buckets: []float64{
1, 2, 3, 4, 5,
10, 20, 30, 40, 50,
100, 200, 300, 400, 500,
1000, 2000, 3000, 4000, 5000,
10000, 20000, 30000, 40000, 50000,
},
},
labelNames)
return ProbeMetricVecs{
alive: alive,
gatewayEnabled: gatewayEnabled,
latency: latency,
latencies: latencies,
enqueues: enqueues,
dequeues: dequeues,
probes: probes,
}
}
// NewWorkerMetrics creates a new ProbeMetrics by scoping to a specific target
// cluster.
func (mv ProbeMetricVecs) NewWorkerMetrics(remoteClusterName string) (*ProbeMetrics, error) {
labels := prometheus.Labels{
gatewayClusterName: remoteClusterName,
}
curriedProbes, err := mv.probes.CurryWith(labels)
if err != nil {
return nil, err
}
gatewayEnabled := mv.gatewayEnabled.With(labels)
gatewayEnabled.Set(0)
return &ProbeMetrics{
gatewayEnabled: gatewayEnabled,
alive: mv.alive.With(labels),
latency: mv.latency.With(labels),
latencies: mv.latencies.With(labels),
probes: curriedProbes,
unregister: func() {
mv.unregister(remoteClusterName)
},
}, nil
}
func (mv ProbeMetricVecs) unregister(remoteClusterName string) {
labels := prometheus.Labels{
gatewayClusterName: remoteClusterName,
}
if !mv.gatewayEnabled.Delete(labels) {
logging.Warnf("unable to delete gateway_enabled metric with labels %s", labels)
}
if !mv.alive.Delete(labels) {
logging.Warnf("unable to delete gateway_alive metric with labels %s", labels)
}
if !mv.latencies.Delete(labels) {
logging.Warnf("unable to delete gateway_probe_latency_ms metric with labels %s", labels)
}
}