-
Notifications
You must be signed in to change notification settings - Fork 153
/
metrics.go
400 lines (385 loc) · 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
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
// Copyright 2020 Anapaya Systems
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package gateway
import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/scionproto/scion/pkg/addr"
"github.com/scionproto/scion/pkg/metrics"
"github.com/scionproto/scion/pkg/snet"
snetmetrics "github.com/scionproto/scion/pkg/snet/metrics"
)
// These are the metrics that should be exposed by any gateway implementation.
var (
IPPktBytesSentTotalMeta = MetricMeta{
Name: "gateway_ippkt_bytes_sent_total",
Help: "Total IP packet bytes sent to remote gateways.",
Labels: []string{"isd_as", "remote_isd_as", "policy_id"},
}
IPPktsSentTotalMeta = MetricMeta{
Name: "gateway_ippkts_sent_total",
Help: "Total number of IP packets sent to remote gateways.",
Labels: []string{"isd_as", "remote_isd_as", "policy_id"},
}
IPPktBytesReceivedTotalMeta = MetricMeta{
Name: "gateway_ippkt_bytes_received_total",
Help: "Total IP packet bytes received from remote gateways.",
Labels: []string{"isd_as", "remote_isd_as"},
}
IPPktsReceivedTotalMeta = MetricMeta{
Name: "gateway_ippkts_received_total",
Help: "Total number of IP packets received from remote gateways.",
Labels: []string{"isd_as", "remote_isd_as"},
}
IPPktBytesLocalSentTotalMeta = MetricMeta{
Name: "gateway_ippkt_bytes_local_sent_total",
Help: "Total IP packet bytes sent to the local network.",
Labels: []string{"isd_as"},
}
IPPktsLocalSentTotalMeta = MetricMeta{
Name: "gateway_ippkts_local_sent_total",
Help: "Total number of IP packets sent to the local network.",
Labels: []string{"isd_as"},
}
IPPktBytesLocalReceivedTotalMeta = MetricMeta{
Name: "gateway_ippkt_bytes_local_received_total",
Help: "Total IP packet bytes received from the local network.",
Labels: []string{},
}
IPPktsLocalReceivedTotalMeta = MetricMeta{
Name: "gateway_ippkts_local_received_total",
Help: "Total number of IP packets received from the local network.",
Labels: []string{},
}
FrameBytesSentTotalMeta = MetricMeta{
Name: "gateway_frame_bytes_sent_total",
Help: "Total frame bytes sent to remote gateways.",
Labels: []string{"isd_as", "remote_isd_as", "policy_id"},
}
FramesSentTotalMeta = MetricMeta{
Name: "gateway_frames_sent_total",
Help: "Total number of frames sent to remote gateways.",
Labels: []string{"isd_as", "remote_isd_as", "policy_id"},
}
FrameBytesReceivedTotalMeta = MetricMeta{
Name: "gateway_frame_bytes_received_total",
Help: "Total frame bytes received from remote gateways.",
Labels: []string{"isd_as", "remote_isd_as"},
}
FramesReceivedTotalMeta = MetricMeta{
Name: "gateway_frames_received_total",
Help: "Total number of frames received from remote gateways.",
Labels: []string{"isd_as", "remote_isd_as"},
}
FramesDiscardedTotalMeta = MetricMeta{
Name: "gateway_frames_discarded_total",
Help: "Total number of discarded frames received from remote gateways.",
Labels: []string{"isd_as", "remote_isd_as", "reason"},
}
IPPktsDiscardedTotalMeta = MetricMeta{
Name: "gateway_ippkts_discarded_total",
Help: "Total number of discarded IP packets received from the local network.",
Labels: []string{"reason"},
}
SendExternalErrorsTotalMeta = MetricMeta{
Name: "gateway_send_external_errors_total",
Help: "Total number of errors when sending frames to the network (WAN).",
Labels: []string{"isd_as"},
}
SendLocalErrorsTotalMeta = MetricMeta{
Name: "gateway_send_local_errors_total",
Help: "Total number of errors when sending IP packets to the network (LAN).",
Labels: []string{"isd_as"},
}
ReceiveExternalErrorsTotalMeta = MetricMeta{
Name: "gateway_receive_external_errors_total",
Help: "Total number of errors when receiving frames from the network (WAN).",
Labels: []string{"isd_as"},
}
ReceiveLocalErrorsTotalMeta = MetricMeta{
Name: "gateway_receive_local_errors_total",
Help: "Total number of errors when receiving IP packets from the network (LAN).",
Labels: []string{"isd_as"},
}
PathsMonitoredMeta = MetricMeta{
Name: "gateway_paths_monitored",
Help: "Total number of paths being monitored by the gateway.",
Labels: []string{"isd_as", "remote_isd_as"},
}
PathProbesSentMeta = MetricMeta{
Name: "gateway_path_probes_sent",
Help: "Number of path probes being sent.",
Labels: []string{"isd_as", "remote_isd_as"},
}
PathProbesReceivedMeta = MetricMeta{
Name: "gateway_path_probes_received",
Help: "Number of replies to the path probes being received.",
Labels: []string{"isd_as", "remote_isd_as"},
}
PathProbesSendErrorsMeta = MetricMeta{
Name: "gateway_path_probes_send_errors",
Help: "Number of send error for path probes.",
Labels: []string{"isd_as", "remote_isd_as"},
}
SessionProbesMeta = MetricMeta{
Name: "gateway_session_probes",
Help: "Number of probes sent per session.",
Labels: []string{"isd_as", "remote_isd_as", "session_id", "policy_id"},
}
SessionProbeRepliesMeta = MetricMeta{
Name: "gateway_session_probe_replies",
Help: "Number of probes received per session.",
Labels: []string{"isd_as", "remote_isd_as", "session_id", "policy_id"},
}
SessionIsHealthyMeta = MetricMeta{
Name: "gateway_session_is_healthy",
Help: "Flag reflecting session healthiness.",
Labels: []string{"isd_as", "remote_isd_as", "session_id", "policy_id"},
}
SessionStateChangesMeta = MetricMeta{
Name: "gateway_session_state_changes",
Help: "The number of state changes per session.",
Labels: []string{"isd_as", "remote_isd_as", "session_id", "policy_id"},
}
SessionPathsAvailableMeta = MetricMeta{
Name: "gateway_session_paths_available",
Help: "Total number of paths available per session policy.",
Labels: []string{"isd_as", "remote_isd_as", "policy_id", "status"},
}
SessionPathChangesMeta = MetricMeta{
Name: "gateway_session_path_changes",
Help: "Total number of path changes per session policy.",
Labels: []string{"isd_as", "remote_isd_as", "session_id", "policy_id"},
}
RemotesMeta = MetricMeta{
Name: "gateway_remotes",
Help: "Total number of discovered remote gateways.",
Labels: []string{"isd_as", "remote_isd_as"},
}
RemoteChangesMeta = MetricMeta{
Name: "gateway_remotes_changes",
Help: "The number of times the remotes number changed.",
Labels: []string{"isd_as", "remote_isd_as"},
}
RemoteDiscoveryErrorsMeta = MetricMeta{
Name: "gateway_remote_discovery_errors_total",
Help: "Total number of errors discovering remote gateways.",
Labels: []string{"isd_as", "remote_isd_as"},
}
RoutingChainHealthyMeta = MetricMeta{
Name: "gateway_routing_chain_healthiness",
Help: "Flag reflecting routing chain healthiness.",
Labels: []string{"isd_as", "routing_chain_id"},
}
RoutingChainAliveSessionsMeta = MetricMeta{
Name: "gateway_routing_chain_alive_sessions",
Help: "The number of alive sessions associated to the routing chain.",
Labels: []string{"isd_as", "routing_chain_id"},
}
RoutingChainSessionChangesMeta = MetricMeta{
Name: "gateway_routing_chain_session_changes",
Help: "The number of session changes in the routing chain.",
Labels: []string{"isd_as", "routing_chain_id"},
}
RoutingChainStateChangesMeta = MetricMeta{
Name: "gateway_routing_chain_state_changes",
Help: "The number of state changes in the routing chain.",
Labels: []string{"isd_as", "routing_chain_id"},
}
PrefixFetchErrorsMeta = MetricMeta{
Name: "gateway_prefix_fetch_errors_total",
Help: "Total number of errors fetching prefixes.",
Labels: []string{"isd_as", "remote_isd_as"},
}
PrefixesAdvertisedMeta = MetricMeta{
Name: "gateway_prefixes_advertised",
Help: "Total number of advertised IP prefixes (outgoing).",
Labels: []string{"isd_as", "remote_isd_as"},
}
PrefixesAcceptedMeta = MetricMeta{
Name: "gateway_prefixes_accepted",
Help: "Total number of accepted IP prefixes (incoming).",
Labels: []string{"isd_as", "remote_isd_as"},
}
PrefixesRejectedMeta = MetricMeta{
Name: "gateway_prefixes_rejected",
Help: "Total number of rejected IP prefixes (incoming).",
Labels: []string{"isd_as", "remote_isd_as"},
}
)
type MetricMeta struct {
Name string
Help string
Labels []string
}
func (mm *MetricMeta) NewCounterVec() *prometheus.CounterVec {
return promauto.NewCounterVec(
prometheus.CounterOpts{
Name: mm.Name,
Help: mm.Help,
},
mm.Labels,
)
}
func (mm *MetricMeta) NewGaugeVec() *prometheus.GaugeVec {
return promauto.NewGaugeVec(
prometheus.GaugeOpts{
Name: mm.Name,
Help: mm.Help,
},
mm.Labels,
)
}
// Metrics defines the metrics exported by the gateway.
type Metrics struct {
// Traffic Metrics
IPPktBytesSentTotal *prometheus.CounterVec
IPPktBytesReceivedTotal *prometheus.CounterVec
IPPktsSentTotal *prometheus.CounterVec
IPPktsReceivedTotal *prometheus.CounterVec
IPPktBytesLocalSentTotal *prometheus.CounterVec
IPPktBytesLocalReceivedTotal *prometheus.CounterVec
IPPktsLocalSentTotal *prometheus.CounterVec
IPPktsLocalReceivedTotal *prometheus.CounterVec
FrameBytesSentTotal *prometheus.CounterVec
FrameBytesReceivedTotal *prometheus.CounterVec
FramesSentTotal *prometheus.CounterVec
FramesReceivedTotal *prometheus.CounterVec
// Error Metrics
FramesDiscardedTotal *prometheus.CounterVec
IPPktsDiscardedTotal *prometheus.CounterVec
SendExternalErrorsTotal *prometheus.CounterVec
SendLocalErrorsTotal *prometheus.CounterVec
ReceiveExternalErrorsTotal *prometheus.CounterVec
ReceiveLocalErrorsTotal *prometheus.CounterVec
// Path Monitoring Metrics
PathsMonitored *prometheus.GaugeVec
SessionPathsAvailable *prometheus.GaugeVec
PathProbesSent *prometheus.CounterVec
PathProbesReceived *prometheus.CounterVec
PathProbesSendErrors *prometheus.CounterVec
// Discovery Metrics
Remotes *prometheus.GaugeVec
RemotesChanges *prometheus.CounterVec
RemoteDiscoveryErrors *prometheus.CounterVec
PrefixFetchErrors *prometheus.CounterVec
PrefixesAdvertised *prometheus.GaugeVec
PrefixesAccepted *prometheus.GaugeVec
PrefixesRejected *prometheus.GaugeVec
// SessionMonitor Metrics
SessionProbes *prometheus.CounterVec
SessionProbeReplies *prometheus.CounterVec
SessionIsHealthy *prometheus.GaugeVec
SessionStateChanges *prometheus.CounterVec
SessionPathChanges *prometheus.CounterVec
// Routing Metrics
RoutingChainHealthy *prometheus.GaugeVec
RoutingChainAliveSessions *prometheus.GaugeVec
RoutingChainSessionChanges *prometheus.CounterVec
RoutingChainStateChanges *prometheus.CounterVec
// Scion Network Metrics
SCIONNetworkMetrics snet.SCIONNetworkMetrics
SCMPErrors metrics.Counter
SCIONPacketConnMetrics snet.SCIONPacketConnMetrics
}
// NewMetrics initializes the metrics for the gateway and registers them with the default registry.
func NewMetrics(ia addr.IA) *Metrics {
labels := map[string]string{
"isd_as": ia.String(),
}
scionPacketConnMetrics := snetmetrics.NewSCIONPacketConnMetrics()
return &Metrics{
IPPktBytesSentTotal: IPPktBytesSentTotalMeta.
NewCounterVec().MustCurryWith(labels),
IPPktsSentTotal: IPPktsSentTotalMeta.
NewCounterVec().MustCurryWith(labels),
IPPktBytesReceivedTotal: IPPktBytesReceivedTotalMeta.
NewCounterVec().MustCurryWith(labels),
IPPktsReceivedTotal: IPPktsReceivedTotalMeta.
NewCounterVec().MustCurryWith(labels),
IPPktBytesLocalSentTotal: IPPktBytesLocalSentTotalMeta.
NewCounterVec().MustCurryWith(labels),
IPPktsLocalSentTotal: IPPktsLocalSentTotalMeta.
NewCounterVec().MustCurryWith(labels),
IPPktBytesLocalReceivedTotal: IPPktBytesLocalReceivedTotalMeta.
NewCounterVec(),
IPPktsLocalReceivedTotal: IPPktsLocalReceivedTotalMeta.
NewCounterVec(),
FrameBytesSentTotal: FrameBytesSentTotalMeta.
NewCounterVec().MustCurryWith(labels),
FramesSentTotal: FramesSentTotalMeta.
NewCounterVec().MustCurryWith(labels),
FrameBytesReceivedTotal: FrameBytesReceivedTotalMeta.
NewCounterVec().MustCurryWith(labels),
FramesReceivedTotal: FramesReceivedTotalMeta.
NewCounterVec().MustCurryWith(labels),
FramesDiscardedTotal: FramesDiscardedTotalMeta.
NewCounterVec().MustCurryWith(labels),
IPPktsDiscardedTotal: IPPktsDiscardedTotalMeta.
NewCounterVec(),
SendExternalErrorsTotal: SendExternalErrorsTotalMeta.
NewCounterVec().MustCurryWith(labels),
SendLocalErrorsTotal: SendLocalErrorsTotalMeta.
NewCounterVec().MustCurryWith(labels),
ReceiveExternalErrorsTotal: ReceiveExternalErrorsTotalMeta.
NewCounterVec().MustCurryWith(labels),
ReceiveLocalErrorsTotal: ReceiveLocalErrorsTotalMeta.
NewCounterVec().MustCurryWith(labels),
PathsMonitored: PathsMonitoredMeta.
NewGaugeVec().MustCurryWith(labels),
PathProbesSent: PathProbesSentMeta.
NewCounterVec().MustCurryWith(labels),
PathProbesReceived: PathProbesReceivedMeta.
NewCounterVec().MustCurryWith(labels),
PathProbesSendErrors: PathProbesSendErrorsMeta.
NewCounterVec().MustCurryWith(labels),
SessionIsHealthy: SessionIsHealthyMeta.
NewGaugeVec().MustCurryWith(labels),
SessionStateChanges: SessionStateChangesMeta.
NewCounterVec().MustCurryWith(labels),
SessionProbes: SessionProbesMeta.
NewCounterVec().MustCurryWith(labels),
SessionProbeReplies: SessionProbeRepliesMeta.
NewCounterVec().MustCurryWith(labels),
SessionPathsAvailable: SessionPathsAvailableMeta.
NewGaugeVec().MustCurryWith(labels),
SessionPathChanges: SessionPathChangesMeta.
NewCounterVec().MustCurryWith(labels),
RoutingChainHealthy: RoutingChainHealthyMeta.
NewGaugeVec().MustCurryWith(labels),
RoutingChainAliveSessions: RoutingChainAliveSessionsMeta.
NewGaugeVec().MustCurryWith(labels),
RoutingChainSessionChanges: RoutingChainSessionChangesMeta.
NewCounterVec().MustCurryWith(labels),
RoutingChainStateChanges: RoutingChainStateChangesMeta.
NewCounterVec().MustCurryWith(labels),
Remotes: RemotesMeta.
NewGaugeVec().MustCurryWith(labels),
RemotesChanges: RemoteChangesMeta.
NewCounterVec().MustCurryWith(labels),
RemoteDiscoveryErrors: RemoteDiscoveryErrorsMeta.
NewCounterVec().MustCurryWith(labels),
PrefixFetchErrors: PrefixFetchErrorsMeta.
NewCounterVec().MustCurryWith(labels),
PrefixesAdvertised: PrefixesAdvertisedMeta.
NewGaugeVec().MustCurryWith(labels),
PrefixesAccepted: PrefixesAcceptedMeta.
NewGaugeVec().MustCurryWith(labels),
PrefixesRejected: PrefixesRejectedMeta.
NewGaugeVec().MustCurryWith(labels),
SCIONNetworkMetrics: snetmetrics.NewSCIONNetworkMetrics(),
SCMPErrors: scionPacketConnMetrics.SCMPErrors,
SCIONPacketConnMetrics: scionPacketConnMetrics,
}
}