Matteo Scandolo | a8bd93e | 2018-09-13 13:36:50 -0700 | [diff] [blame] | 1 | // 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 | |
| 15 | package main |
| 16 | |
Scott Baker | e8537af | 2018-10-22 14:53:44 -0700 | [diff] [blame] | 17 | import ( |
| 18 | "github.com/prometheus/client_golang/prometheus" |
| 19 | ) |
Matteo Scandolo | a8bd93e | 2018-09-13 13:36:50 -0700 | [diff] [blame] | 20 | |
| 21 | var ( |
| 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 | |
| 68 | func export(kpi KPI) { |
| 69 | |
| 70 | for _, data := range kpi.SliceDatas { |
Scott Baker | e8537af | 2018-10-22 14:53:44 -0700 | [diff] [blame] | 71 | 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 Scandolo | a8bd93e | 2018-09-13 13:36:50 -0700 | [diff] [blame] | 82 | |
Scott Baker | e8537af | 2018-10-22 14:53:44 -0700 | [diff] [blame] | 83 | 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 Scandolo | a8bd93e | 2018-09-13 13:36:50 -0700 | [diff] [blame] | 92 | |
Scott Baker | e8537af | 2018-10-22 14:53:44 -0700 | [diff] [blame] | 93 | 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 Scandolo | a8bd93e | 2018-09-13 13:36:50 -0700 | [diff] [blame] | 102 | |
Scott Baker | e8537af | 2018-10-22 14:53:44 -0700 | [diff] [blame] | 103 | 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 Scandolo | a8bd93e | 2018-09-13 13:36:50 -0700 | [diff] [blame] | 112 | |
Scott Baker | e8537af | 2018-10-22 14:53:44 -0700 | [diff] [blame] | 113 | 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 Scandolo | a8bd93e | 2018-09-13 13:36:50 -0700 | [diff] [blame] | 122 | |
Scott Baker | e8537af | 2018-10-22 14:53:44 -0700 | [diff] [blame] | 123 | 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 Scandolo | a8bd93e | 2018-09-13 13:36:50 -0700 | [diff] [blame] | 132 | |
Scott Baker | e8537af | 2018-10-22 14:53:44 -0700 | [diff] [blame] | 133 | // TODO add metrics for: |
| 134 | // TxBcastPackets |
| 135 | // TxUnicastPackets |
| 136 | // TxMulticastPackets |
| 137 | // RxBcastPackets |
| 138 | // RxMulticastPackets |
Matteo Scandolo | a8bd93e | 2018-09-13 13:36:50 -0700 | [diff] [blame] | 139 | |
Scott Baker | e8537af | 2018-10-22 14:53:44 -0700 | [diff] [blame] | 140 | 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 Scandolo | a8bd93e | 2018-09-13 13:36:50 -0700 | [diff] [blame] | 194 | } |
| 195 | } |