Matteo Scandolo | aab36db | 2018-10-09 19:54:11 -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 | |
| 17 | import ( |
| 18 | "github.com/prometheus/client_golang/prometheus" |
| 19 | ) |
| 20 | |
| 21 | var ( |
| 22 | onosTxBytesTotal = prometheus.NewGaugeVec( |
| 23 | prometheus.GaugeOpts{ |
| 24 | Name: "onos_tx_bytes_total", |
| 25 | Help: "Number of total bytes transmitted", |
| 26 | }, |
| 27 | []string{"device_id", "port_id"}, |
| 28 | ) |
| 29 | onosRxBytesTotal = prometheus.NewGaugeVec( |
| 30 | prometheus.GaugeOpts{ |
| 31 | Name: "onos_rx_bytes_total", |
| 32 | Help: "Number of total bytes received", |
| 33 | }, |
| 34 | []string{"device_id", "port_id"}, |
| 35 | ) |
| 36 | onosTxPacketsTotal = prometheus.NewGaugeVec( |
| 37 | prometheus.GaugeOpts{ |
| 38 | Name: "onos_tx_packets_total", |
| 39 | Help: "Number of total packets transmitted", |
| 40 | }, |
| 41 | []string{"device_id", "port_id"}, |
| 42 | ) |
| 43 | onosRxPacketsTotal = prometheus.NewGaugeVec( |
| 44 | prometheus.GaugeOpts{ |
| 45 | Name: "onos_rx_packets_total", |
| 46 | Help: "Number of total packets received", |
| 47 | }, |
| 48 | []string{"device_id", "port_id"}, |
| 49 | ) |
| 50 | |
| 51 | onosTxDropPacketsTotal = prometheus.NewGaugeVec( |
| 52 | prometheus.GaugeOpts{ |
| 53 | Name: "onos_tx_drop_packets_total", |
| 54 | Help: "Number of total transmitted packets dropped", |
| 55 | }, |
| 56 | []string{"device_id", "port_id"}, |
| 57 | ) |
| 58 | |
| 59 | onosRxDropPacketsTotal = prometheus.NewGaugeVec( |
| 60 | prometheus.GaugeOpts{ |
| 61 | Name: "onos_rx_drop_packets_total", |
| 62 | Help: "Number of total received packets dropped", |
| 63 | }, |
| 64 | []string{"device_id", "port_id"}, |
| 65 | ) |
| 66 | ) |
| 67 | |
| 68 | func exportOnosKPI(kpi OnosKPI) { |
| 69 | |
| 70 | for _, data := range kpi.Ports { |
| 71 | |
| 72 | onosTxBytesTotal.WithLabelValues( |
| 73 | kpi.DeviceID, |
| 74 | data.PortID, |
| 75 | ).Set(data.TxBytes) |
| 76 | |
| 77 | onosRxBytesTotal.WithLabelValues( |
| 78 | kpi.DeviceID, |
| 79 | data.PortID, |
| 80 | ).Set(data.RxBytes) |
| 81 | |
| 82 | onosTxPacketsTotal.WithLabelValues( |
| 83 | kpi.DeviceID, |
| 84 | data.PortID, |
| 85 | ).Set(data.TxPackets) |
| 86 | |
| 87 | onosRxPacketsTotal.WithLabelValues( |
| 88 | kpi.DeviceID, |
| 89 | data.PortID, |
| 90 | ).Set(data.RxPackets) |
| 91 | |
| 92 | onosTxDropPacketsTotal.WithLabelValues( |
| 93 | kpi.DeviceID, |
| 94 | data.PortID, |
| 95 | ).Set(data.TxPacketsDrop) |
| 96 | |
| 97 | onosRxDropPacketsTotal.WithLabelValues( |
| 98 | kpi.DeviceID, |
| 99 | data.PortID, |
| 100 | ).Set(data.RxPacketsDrop) |
| 101 | |
| 102 | } |
| 103 | } |