blob: a1bc32736e13f0fbd736943b8d285aba5cdec8d4 [file] [log] [blame]
Matteo Scandoloa8bd93e2018-09-13 13:36:50 -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
Scott Bakere8537af2018-10-22 14:53:44 -070017import (
18 "github.com/prometheus/client_golang/prometheus"
19)
Matteo Scandoloa8bd93e2018-09-13 13:36:50 -070020
21var (
22 txBytesTotal = prometheus.NewGaugeVec(
23 prometheus.GaugeOpts{
24 Name: "tx_bytes_total",
25 Help: "Number of total bytes transmitted",
26 },
27 []string{"logical_device_id", "serial_number", "device_id", "interface_id", "pon_id", "port_number", "title"},
28 )
29 rxBytesTotal = prometheus.NewGaugeVec(
30 prometheus.GaugeOpts{
31 Name: "rx_bytes_total",
32 Help: "Number of total bytes received",
33 },
34 []string{"logical_device_id", "serial_number", "device_id", "interface_id", "pon_id", "port_number", "title"},
35 )
36 txPacketsTotal = prometheus.NewGaugeVec(
37 prometheus.GaugeOpts{
38 Name: "tx_packets_total",
39 Help: "Number of total packets transmitted",
40 },
41 []string{"logical_device_id", "serial_number", "device_id", "interface_id", "pon_id", "port_number", "title"},
42 )
43 rxPacketsTotal = prometheus.NewGaugeVec(
44 prometheus.GaugeOpts{
45 Name: "rx_packets_total",
46 Help: "Number of total packets received",
47 },
48 []string{"logical_device_id", "serial_number", "device_id", "interface_id", "pon_id", "port_number", "title"},
49 )
50
51 txErrorPacketsTotal = prometheus.NewGaugeVec(
52 prometheus.GaugeOpts{
53 Name: "tx_error_packets_total",
54 Help: "Number of total transmitted packets error",
55 },
56 []string{"logical_device_id", "serial_number", "device_id", "interface_id", "pon_id", "port_number", "title"},
57 )
58
59 rxErrorPacketsTotal = prometheus.NewGaugeVec(
60 prometheus.GaugeOpts{
61 Name: "rx_error_packets_total",
62 Help: "Number of total received packets error",
63 },
64 []string{"logical_device_id", "serial_number", "device_id", "interface_id", "pon_id", "port_number", "title"},
65 )
66)
67
68func export(kpi KPI) {
69
70 for _, data := range kpi.SliceDatas {
Scott Bakere8537af2018-10-22 14:53:44 -070071 switch title := data.Metadata.Title; title {
72 case "Ethernet", "PON":
73 txBytesTotal.WithLabelValues(
74 data.Metadata.LogicalDeviceID,
75 data.Metadata.SerialNumber,
76 data.Metadata.DeviceID,
77 data.Metadata.Context.InterfaceID,
78 data.Metadata.Context.PonID,
79 data.Metadata.Context.PortNumber,
80 data.Metadata.Title,
81 ).Set(data.Metrics.TxBytes)
Matteo Scandoloa8bd93e2018-09-13 13:36:50 -070082
Scott Bakere8537af2018-10-22 14:53:44 -070083 rxBytesTotal.WithLabelValues(
84 data.Metadata.LogicalDeviceID,
85 data.Metadata.SerialNumber,
86 data.Metadata.DeviceID,
87 data.Metadata.Context.InterfaceID,
88 data.Metadata.Context.PonID,
89 data.Metadata.Context.PortNumber,
90 data.Metadata.Title,
91 ).Set(data.Metrics.RxBytes)
Matteo Scandoloa8bd93e2018-09-13 13:36:50 -070092
Scott Bakere8537af2018-10-22 14:53:44 -070093 txPacketsTotal.WithLabelValues(
94 data.Metadata.LogicalDeviceID,
95 data.Metadata.SerialNumber,
96 data.Metadata.DeviceID,
97 data.Metadata.Context.InterfaceID,
98 data.Metadata.Context.PonID,
99 data.Metadata.Context.PortNumber,
100 data.Metadata.Title,
101 ).Set(data.Metrics.TxPackets)
Matteo Scandoloa8bd93e2018-09-13 13:36:50 -0700102
Scott Bakere8537af2018-10-22 14:53:44 -0700103 rxPacketsTotal.WithLabelValues(
104 data.Metadata.LogicalDeviceID,
105 data.Metadata.SerialNumber,
106 data.Metadata.DeviceID,
107 data.Metadata.Context.InterfaceID,
108 data.Metadata.Context.PonID,
109 data.Metadata.Context.PortNumber,
110 data.Metadata.Title,
111 ).Set(data.Metrics.RxPackets)
Matteo Scandoloa8bd93e2018-09-13 13:36:50 -0700112
Scott Bakere8537af2018-10-22 14:53:44 -0700113 txErrorPacketsTotal.WithLabelValues(
114 data.Metadata.LogicalDeviceID,
115 data.Metadata.SerialNumber,
116 data.Metadata.DeviceID,
117 data.Metadata.Context.InterfaceID,
118 data.Metadata.Context.PonID,
119 data.Metadata.Context.PortNumber,
120 data.Metadata.Title,
121 ).Set(data.Metrics.TxErrorPackets)
Matteo Scandoloa8bd93e2018-09-13 13:36:50 -0700122
Scott Bakere8537af2018-10-22 14:53:44 -0700123 rxErrorPacketsTotal.WithLabelValues(
124 data.Metadata.LogicalDeviceID,
125 data.Metadata.SerialNumber,
126 data.Metadata.DeviceID,
127 data.Metadata.Context.InterfaceID,
128 data.Metadata.Context.PonID,
129 data.Metadata.Context.PortNumber,
130 data.Metadata.Title,
131 ).Set(data.Metrics.RxErrorPackets)
Matteo Scandoloa8bd93e2018-09-13 13:36:50 -0700132
Scott Bakere8537af2018-10-22 14:53:44 -0700133 // TODO add metrics for:
134 // TxBcastPackets
135 // TxUnicastPackets
136 // TxMulticastPackets
137 // RxBcastPackets
138 // RxMulticastPackets
Matteo Scandoloa8bd93e2018-09-13 13:36:50 -0700139
Scott Bakere8537af2018-10-22 14:53:44 -0700140 case "Ethernet_Bridge_Port_History":
141 if data.Metadata.Context.Upstream == "True" {
142 // ONU. Extended Ethernet statistics.
143 txPacketsTotal.WithLabelValues(
144 data.Metadata.LogicalDeviceID,
145 data.Metadata.SerialNumber,
146 data.Metadata.DeviceID,
147 "NA", // InterfaceID
148 "NA", // PonID
149 "NA", // PortNumber
150 data.Metadata.Title,
151 ).Add(data.Metrics.Packets)
152
153 txBytesTotal.WithLabelValues(
154 data.Metadata.LogicalDeviceID,
155 data.Metadata.SerialNumber,
156 data.Metadata.DeviceID,
157 "NA", // InterfaceID
158 "NA", // PonID
159 "NA", // PortNumber
160 data.Metadata.Title,
161 ).Add(data.Metrics.Octets)
162 } else {
163 // ONU. Extended Ethernet statistics.
164 rxPacketsTotal.WithLabelValues(
165 data.Metadata.LogicalDeviceID,
166 data.Metadata.SerialNumber,
167 data.Metadata.DeviceID,
168 "NA", // InterfaceID
169 "NA", // PonID
170 "NA", // PortNumber
171 data.Metadata.Title,
172 ).Add(data.Metrics.Packets)
173
174 rxBytesTotal.WithLabelValues(
175 data.Metadata.LogicalDeviceID,
176 data.Metadata.SerialNumber,
177 data.Metadata.DeviceID,
178 "NA", // InterfaceID
179 "NA", // PonID
180 "NA", // PortNumber
181 data.Metadata.Title,
182 ).Add(data.Metrics.Octets)
183 }
184
185 case "Ethernet_UNI_History":
186 // ONU. Do nothing.
187
188 case "FEC_History":
189 // ONU. Do Nothing.
190
191 case "voltha.internal":
192 // Voltha Internal. Do nothing.
193 }
Matteo Scandoloa8bd93e2018-09-13 13:36:50 -0700194 }
195}