blob: 7e604b57f9efafe31e7281181775b775fb760047 [file] [log] [blame]
Matteo Scandoloaab36db2018-10-09 19:54:11 -07001// Copyright 2018 Open Networking Foundation
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package main
16
17import (
Ganesh Bhure8d0c9942019-05-24 11:42:09 +053018 "encoding/json"
19 "log"
Matteo Scandoloaab36db2018-10-09 19:54:11 -070020 "github.com/prometheus/client_golang/prometheus"
Ganesh Bhure8d0c9942019-05-24 11:42:09 +053021 "gerrit.opencord.org/kafka-topic-exporter/common/logger"
Matteo Scandoloaab36db2018-10-09 19:54:11 -070022)
23
24var (
Ganesh Bhure8d0c9942019-05-24 11:42:09 +053025 // voltha kpis
Matteo Scandoloaab36db2018-10-09 19:54:11 -070026 volthaTxBytesTotal = prometheus.NewGaugeVec(
27 prometheus.GaugeOpts{
28 Name: "voltha_tx_bytes_total",
29 Help: "Number of total bytes transmitted",
30 },
31 []string{"logical_device_id", "serial_number", "device_id", "interface_id", "pon_id", "port_number", "title"},
32 )
33 volthaRxBytesTotal = prometheus.NewGaugeVec(
34 prometheus.GaugeOpts{
35 Name: "voltha_rx_bytes_total",
36 Help: "Number of total bytes received",
37 },
38 []string{"logical_device_id", "serial_number", "device_id", "interface_id", "pon_id", "port_number", "title"},
39 )
40 volthaTxPacketsTotal = prometheus.NewGaugeVec(
41 prometheus.GaugeOpts{
42 Name: "voltha_tx_packets_total",
43 Help: "Number of total packets transmitted",
44 },
45 []string{"logical_device_id", "serial_number", "device_id", "interface_id", "pon_id", "port_number", "title"},
46 )
47 volthaRxPacketsTotal = prometheus.NewGaugeVec(
48 prometheus.GaugeOpts{
49 Name: "voltha_rx_packets_total",
50 Help: "Number of total packets received",
51 },
52 []string{"logical_device_id", "serial_number", "device_id", "interface_id", "pon_id", "port_number", "title"},
53 )
54
55 volthaTxErrorPacketsTotal = prometheus.NewGaugeVec(
56 prometheus.GaugeOpts{
57 Name: "voltha_tx_error_packets_total",
58 Help: "Number of total transmitted packets error",
59 },
60 []string{"logical_device_id", "serial_number", "device_id", "interface_id", "pon_id", "port_number", "title"},
61 )
62
63 volthaRxErrorPacketsTotal = prometheus.NewGaugeVec(
64 prometheus.GaugeOpts{
65 Name: "voltha_rx_error_packets_total",
66 Help: "Number of total received packets error",
67 },
68 []string{"logical_device_id", "serial_number", "device_id", "interface_id", "pon_id", "port_number", "title"},
69 )
Ganesh Bhure8d0c9942019-05-24 11:42:09 +053070
71 // onos kpis
72 onosTxBytesTotal = prometheus.NewGaugeVec(
73 prometheus.GaugeOpts{
74 Name: "onos_tx_bytes_total",
75 Help: "Number of total bytes transmitted",
76 },
77 []string{"device_id", "port_id"},
78 )
79 onosRxBytesTotal = prometheus.NewGaugeVec(
80 prometheus.GaugeOpts{
81 Name: "onos_rx_bytes_total",
82 Help: "Number of total bytes received",
83 },
84 []string{"device_id", "port_id"},
85 )
86 onosTxPacketsTotal = prometheus.NewGaugeVec(
87 prometheus.GaugeOpts{
88 Name: "onos_tx_packets_total",
89 Help: "Number of total packets transmitted",
90 },
91 []string{"device_id", "port_id"},
92 )
93 onosRxPacketsTotal = prometheus.NewGaugeVec(
94 prometheus.GaugeOpts{
95 Name: "onos_rx_packets_total",
96 Help: "Number of total packets received",
97 },
98 []string{"device_id", "port_id"},
99 )
100
101 onosTxDropPacketsTotal = prometheus.NewGaugeVec(
102 prometheus.GaugeOpts{
103 Name: "onos_tx_drop_packets_total",
104 Help: "Number of total transmitted packets dropped",
105 },
106 []string{"device_id", "port_id"},
107 )
108
109 onosRxDropPacketsTotal = prometheus.NewGaugeVec(
110 prometheus.GaugeOpts{
111 Name: "onos_rx_drop_packets_total",
112 Help: "Number of total received packets dropped",
113 },
114 []string{"device_id", "port_id"},
115 )
kartikey dubey72ef3b82019-05-27 06:50:04 +0000116
117 // onos.aaa kpis
118 onosaaaRxAcceptResponses = prometheus.NewGauge(
119 prometheus.GaugeOpts{
120 Name: "onosaaa_rx_accept_responses",
121 Help: "Number of access accept packets received from the server",
122 })
123 onosaaaRxRejectResponses = prometheus.NewGauge(
124 prometheus.GaugeOpts{
125 Name: "onosaaa_rx_reject_responses",
126 Help: "Number of access reject packets received from the server",
127 })
128 onosaaaRxChallengeResponses = prometheus.NewGauge(
129 prometheus.GaugeOpts{
130 Name: "onosaaa_rx_challenge_response",
131 Help: "Number of access challenge packets received from the server",
132 })
133 onosaaaTxAccessRequests = prometheus.NewGauge(
134 prometheus.GaugeOpts{
135 Name: "onosaaa_tx_access_requests",
136 Help: "Number of access request packets sent to the server",
137 })
138 onosaaaRxInvalidValidators = prometheus.NewGauge(
139 prometheus.GaugeOpts{
140 Name: "onosaaa_rx_invalid_validators",
141 Help: "Number of access response packets received from the server with an invalid validator",
142 })
143 onosaaaRxUnknownType = prometheus.NewGauge(
144 prometheus.GaugeOpts{
145 Name: "onosaaa_rx_unknown_type",
146 Help: "Number of packets of an unknown RADIUS type received from the accounting server",
147 })
148 onosaaaPendingRequests = prometheus.NewGauge(
149 prometheus.GaugeOpts{
150 Name: "onosaaa_pending_responses",
151 Help: "Number of access request packets pending a response from the server",
152 })
153 onosaaaRxDroppedResponses = prometheus.NewGauge(
154 prometheus.GaugeOpts{
155 Name: "onosaaa_rx_dropped_responses",
156 Help: "Number of dropped packets received from the accounting server",
157 })
158 onosaaaRxMalformedResponses = prometheus.NewGauge(
159 prometheus.GaugeOpts{
160 Name: "onosaaa_rx_malformed_responses",
161 Help: "Number of malformed access response packets received from the server",
162 })
163 onosaaaRxUnknownserver = prometheus.NewGauge(
164 prometheus.GaugeOpts{
165 Name: "onosaaa_rx_from_unknown_server",
166 Help: "Number of packets received from an unknown server",
167 })
168 onosaaaRequestRttMillis = prometheus.NewGauge(
169 prometheus.GaugeOpts{
170 Name: "onosaaa_request_rttmillis",
171 Help: "Roundtrip packet time to the accounting server in Miliseconds",
172 })
173 onosaaaRequestReTx = prometheus.NewGauge(
174 prometheus.GaugeOpts{
175 Name: "onosaaa_request_re_tx",
176 Help: "Number of access request packets retransmitted to the server",
177 })
Matteo Scandoloaab36db2018-10-09 19:54:11 -0700178)
179
180func exportVolthaKPI(kpi VolthaKPI) {
181
182 for _, data := range kpi.SliceDatas {
183 switch title := data.Metadata.Title; title {
184 case "Ethernet", "PON":
185 volthaTxBytesTotal.WithLabelValues(
186 data.Metadata.LogicalDeviceID,
187 data.Metadata.SerialNumber,
188 data.Metadata.DeviceID,
189 data.Metadata.Context.InterfaceID,
190 data.Metadata.Context.PonID,
191 data.Metadata.Context.PortNumber,
192 data.Metadata.Title,
193 ).Set(data.Metrics.TxBytes)
194
195 volthaRxBytesTotal.WithLabelValues(
196 data.Metadata.LogicalDeviceID,
197 data.Metadata.SerialNumber,
198 data.Metadata.DeviceID,
199 data.Metadata.Context.InterfaceID,
200 data.Metadata.Context.PonID,
201 data.Metadata.Context.PortNumber,
202 data.Metadata.Title,
203 ).Set(data.Metrics.RxBytes)
204
205 volthaTxPacketsTotal.WithLabelValues(
206 data.Metadata.LogicalDeviceID,
207 data.Metadata.SerialNumber,
208 data.Metadata.DeviceID,
209 data.Metadata.Context.InterfaceID,
210 data.Metadata.Context.PonID,
211 data.Metadata.Context.PortNumber,
212 data.Metadata.Title,
213 ).Set(data.Metrics.TxPackets)
214
215 volthaRxPacketsTotal.WithLabelValues(
216 data.Metadata.LogicalDeviceID,
217 data.Metadata.SerialNumber,
218 data.Metadata.DeviceID,
219 data.Metadata.Context.InterfaceID,
220 data.Metadata.Context.PonID,
221 data.Metadata.Context.PortNumber,
222 data.Metadata.Title,
223 ).Set(data.Metrics.RxPackets)
224
225 volthaTxErrorPacketsTotal.WithLabelValues(
226 data.Metadata.LogicalDeviceID,
227 data.Metadata.SerialNumber,
228 data.Metadata.DeviceID,
229 data.Metadata.Context.InterfaceID,
230 data.Metadata.Context.PonID,
231 data.Metadata.Context.PortNumber,
232 data.Metadata.Title,
233 ).Set(data.Metrics.TxErrorPackets)
234
235 volthaRxErrorPacketsTotal.WithLabelValues(
236 data.Metadata.LogicalDeviceID,
237 data.Metadata.SerialNumber,
238 data.Metadata.DeviceID,
239 data.Metadata.Context.InterfaceID,
240 data.Metadata.Context.PonID,
241 data.Metadata.Context.PortNumber,
242 data.Metadata.Title,
243 ).Set(data.Metrics.RxErrorPackets)
244
245 // TODO add metrics for:
246 // TxBcastPackets
247 // TxUnicastPackets
248 // TxMulticastPackets
249 // RxBcastPackets
250 // RxMulticastPackets
251
252 case "Ethernet_Bridge_Port_History":
253 if data.Metadata.Context.Upstream == "True" {
254 // ONU. Extended Ethernet statistics.
255 volthaTxPacketsTotal.WithLabelValues(
256 data.Metadata.LogicalDeviceID,
257 data.Metadata.SerialNumber,
258 data.Metadata.DeviceID,
259 "NA", // InterfaceID
260 "NA", // PonID
261 "NA", // PortNumber
262 data.Metadata.Title,
263 ).Add(data.Metrics.Packets)
264
265 volthaTxBytesTotal.WithLabelValues(
266 data.Metadata.LogicalDeviceID,
267 data.Metadata.SerialNumber,
268 data.Metadata.DeviceID,
269 "NA", // InterfaceID
270 "NA", // PonID
271 "NA", // PortNumber
272 data.Metadata.Title,
273 ).Add(data.Metrics.Octets)
274 } else {
275 // ONU. Extended Ethernet statistics.
276 volthaRxPacketsTotal.WithLabelValues(
277 data.Metadata.LogicalDeviceID,
278 data.Metadata.SerialNumber,
279 data.Metadata.DeviceID,
280 "NA", // InterfaceID
281 "NA", // PonID
282 "NA", // PortNumber
283 data.Metadata.Title,
284 ).Add(data.Metrics.Packets)
285
286 volthaRxBytesTotal.WithLabelValues(
287 data.Metadata.LogicalDeviceID,
288 data.Metadata.SerialNumber,
289 data.Metadata.DeviceID,
290 "NA", // InterfaceID
291 "NA", // PonID
292 "NA", // PortNumber
293 data.Metadata.Title,
294 ).Add(data.Metrics.Octets)
295 }
296
297 case "Ethernet_UNI_History":
298 // ONU. Do nothing.
299
300 case "FEC_History":
301 // ONU. Do Nothing.
302
303 volthaTxBytesTotal.WithLabelValues(
304 data.Metadata.LogicalDeviceID,
305 data.Metadata.SerialNumber,
306 data.Metadata.DeviceID,
307 data.Metadata.Context.InterfaceID,
308 data.Metadata.Context.PonID,
309 data.Metadata.Context.PortNumber,
310 data.Metadata.Title,
311 ).Set(data.Metrics.TxBytes)
312
313 volthaRxBytesTotal.WithLabelValues(
314 data.Metadata.LogicalDeviceID,
315 data.Metadata.SerialNumber,
316 data.Metadata.DeviceID,
317 data.Metadata.Context.InterfaceID,
318 data.Metadata.Context.PonID,
319 data.Metadata.Context.PortNumber,
320 data.Metadata.Title,
321 ).Set(data.Metrics.RxBytes)
322
323 volthaTxPacketsTotal.WithLabelValues(
324 data.Metadata.LogicalDeviceID,
325 data.Metadata.SerialNumber,
326 data.Metadata.DeviceID,
327 data.Metadata.Context.InterfaceID,
328 data.Metadata.Context.PonID,
329 data.Metadata.Context.PortNumber,
330 data.Metadata.Title,
331 ).Set(data.Metrics.TxPackets)
332
333 volthaRxPacketsTotal.WithLabelValues(
334 data.Metadata.LogicalDeviceID,
335 data.Metadata.SerialNumber,
336 data.Metadata.DeviceID,
337 data.Metadata.Context.InterfaceID,
338 data.Metadata.Context.PonID,
339 data.Metadata.Context.PortNumber,
340 data.Metadata.Title,
341 ).Set(data.Metrics.RxPackets)
342
343 volthaTxErrorPacketsTotal.WithLabelValues(
344 data.Metadata.LogicalDeviceID,
345 data.Metadata.SerialNumber,
346 data.Metadata.DeviceID,
347 data.Metadata.Context.InterfaceID,
348 data.Metadata.Context.PonID,
349 data.Metadata.Context.PortNumber,
350 data.Metadata.Title,
351 ).Set(data.Metrics.TxErrorPackets)
352
353 volthaRxErrorPacketsTotal.WithLabelValues(
354 data.Metadata.LogicalDeviceID,
355 data.Metadata.SerialNumber,
356 data.Metadata.DeviceID,
357 data.Metadata.Context.InterfaceID,
358 data.Metadata.Context.PonID,
359 data.Metadata.Context.PortNumber,
360 data.Metadata.Title,
361 ).Set(data.Metrics.RxErrorPackets)
362
363 // TODO add metrics for:
364 // TxBcastPackets
365 // TxUnicastPackets
366 // TxMulticastPackets
367 // RxBcastPackets
368 // RxMulticastPackets
369
370 case "voltha.internal":
371 // Voltha Internal. Do nothing.
372 }
373 }
374}
Ganesh Bhure8d0c9942019-05-24 11:42:09 +0530375
376func exportOnosKPI(kpi OnosKPI) {
377
378 for _, data := range kpi.Ports {
379
380 onosTxBytesTotal.WithLabelValues(
381 kpi.DeviceID,
382 data.PortID,
383 ).Set(data.TxBytes)
384
385 onosRxBytesTotal.WithLabelValues(
386 kpi.DeviceID,
387 data.PortID,
388 ).Set(data.RxBytes)
389
390 onosTxPacketsTotal.WithLabelValues(
391 kpi.DeviceID,
392 data.PortID,
393 ).Set(data.TxPackets)
394
395 onosRxPacketsTotal.WithLabelValues(
396 kpi.DeviceID,
397 data.PortID,
398 ).Set(data.RxPackets)
399
400 onosTxDropPacketsTotal.WithLabelValues(
401 kpi.DeviceID,
402 data.PortID,
403 ).Set(data.TxPacketsDrop)
404
405 onosRxDropPacketsTotal.WithLabelValues(
406 kpi.DeviceID,
407 data.PortID,
408 ).Set(data.RxPacketsDrop)
409 }
410}
411
412func exportImporterKPI(kpi ImporterKPI) {
413 // TODO: add metrics for importer data
414 logger.Info("To be implemented")
415}
416
kartikey dubey72ef3b82019-05-27 06:50:04 +0000417func exportOnosAaaKPI(kpi OnosAaaKPI) {
418
419 onosaaaRxAcceptResponses.Set(kpi.RxAcceptResponses)
420
421 onosaaaRxRejectResponses.Set(kpi.RxRejectResponses)
422
423 onosaaaRxChallengeResponses.Set(kpi.RxChallengeResponses)
424
425 onosaaaTxAccessRequests.Set(kpi.TxAccessRequests)
426
427 onosaaaRxInvalidValidators.Set(kpi.RxInvalidValidators)
428
429 onosaaaRxUnknownType.Set(kpi.RxUnknownType)
430
431 onosaaaPendingRequests.Set(kpi.PendingRequests)
432
433 onosaaaRxDroppedResponses.Set(kpi.RxDroppedResponses)
434
435 onosaaaRxMalformedResponses.Set(kpi.RxMalformedResponses)
436
437 onosaaaRxUnknownserver.Set(kpi.RxUnknownserver)
438
439 onosaaaRequestRttMillis.Set(kpi.RequestRttMillis)
440
441 onosaaaRequestReTx.Set(kpi.RequestReTx)
442}
443
Ganesh Bhure8d0c9942019-05-24 11:42:09 +0530444func export(topic *string, data []byte) {
445 switch *topic {
446 case "voltha.kpis":
447 kpi := VolthaKPI{}
448 err := json.Unmarshal(data, &kpi)
449 if err != nil {
450 log.Fatal(err)
451 }
452 exportVolthaKPI(kpi)
453 case "onos.kpis":
454 kpi := OnosKPI{}
455 err := json.Unmarshal(data, &kpi)
456 if err != nil {
457 log.Fatal(err)
458 }
459 exportOnosKPI(kpi)
460 case "importer.kpis":
461 kpi := ImporterKPI{}
462 err := json.Unmarshal(data, &kpi)
463 if err != nil {
464 log.Fatal(err)
465 }
466 exportImporterKPI(kpi)
kartikey dubey72ef3b82019-05-27 06:50:04 +0000467 case "onos.aaa.stats.kpis":
468 kpi := OnosAaaKPI{}
469 err := json.Unmarshal(data, &kpi)
470 if err != nil {
471 log.Fatal(err)
472 }
473 exportOnosAaaKPI(kpi)
Ganesh Bhure8d0c9942019-05-24 11:42:09 +0530474 default:
475 logger.Warn("Unexpected export. Should not come here")
476 }
477}