blob: 15ce59913e34c39b3f38f757d07582db63c7e6fa [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
17import "github.com/prometheus/client_golang/prometheus"
18
19var (
20 txBytesTotal = prometheus.NewGaugeVec(
21 prometheus.GaugeOpts{
22 Name: "tx_bytes_total",
23 Help: "Number of total bytes transmitted",
24 },
25 []string{"logical_device_id", "serial_number", "device_id", "interface_id", "pon_id", "port_number", "title"},
26 )
27 rxBytesTotal = prometheus.NewGaugeVec(
28 prometheus.GaugeOpts{
29 Name: "rx_bytes_total",
30 Help: "Number of total bytes received",
31 },
32 []string{"logical_device_id", "serial_number", "device_id", "interface_id", "pon_id", "port_number", "title"},
33 )
34 txPacketsTotal = prometheus.NewGaugeVec(
35 prometheus.GaugeOpts{
36 Name: "tx_packets_total",
37 Help: "Number of total packets transmitted",
38 },
39 []string{"logical_device_id", "serial_number", "device_id", "interface_id", "pon_id", "port_number", "title"},
40 )
41 rxPacketsTotal = prometheus.NewGaugeVec(
42 prometheus.GaugeOpts{
43 Name: "rx_packets_total",
44 Help: "Number of total packets received",
45 },
46 []string{"logical_device_id", "serial_number", "device_id", "interface_id", "pon_id", "port_number", "title"},
47 )
48
49 txErrorPacketsTotal = prometheus.NewGaugeVec(
50 prometheus.GaugeOpts{
51 Name: "tx_error_packets_total",
52 Help: "Number of total transmitted packets error",
53 },
54 []string{"logical_device_id", "serial_number", "device_id", "interface_id", "pon_id", "port_number", "title"},
55 )
56
57 rxErrorPacketsTotal = prometheus.NewGaugeVec(
58 prometheus.GaugeOpts{
59 Name: "rx_error_packets_total",
60 Help: "Number of total received packets error",
61 },
62 []string{"logical_device_id", "serial_number", "device_id", "interface_id", "pon_id", "port_number", "title"},
63 )
64)
65
66func export(kpi KPI) {
67
68 for _, data := range kpi.SliceDatas {
69 txBytesTotal.WithLabelValues(
70 data.Metadata.LogicalDeviceID,
71 data.Metadata.SerialNumber,
72 data.Metadata.DeviceID,
73 data.Metadata.Context.InterfaceID,
74 data.Metadata.Context.PonID,
75 data.Metadata.Context.PortNumber,
76 data.Metadata.Title,
77 ).Set(data.Metrics.TxBytes)
78
79 rxBytesTotal.WithLabelValues(
80 data.Metadata.LogicalDeviceID,
81 data.Metadata.SerialNumber,
82 data.Metadata.DeviceID,
83 data.Metadata.Context.InterfaceID,
84 data.Metadata.Context.PonID,
85 data.Metadata.Context.PortNumber,
86 data.Metadata.Title,
87 ).Set(data.Metrics.RxBytes)
88
89 txPacketsTotal.WithLabelValues(
90 data.Metadata.LogicalDeviceID,
91 data.Metadata.SerialNumber,
92 data.Metadata.DeviceID,
93 data.Metadata.Context.InterfaceID,
94 data.Metadata.Context.PonID,
95 data.Metadata.Context.PortNumber,
96 data.Metadata.Title,
97 ).Set(data.Metrics.TxPackets)
98
99 rxPacketsTotal.WithLabelValues(
100 data.Metadata.LogicalDeviceID,
101 data.Metadata.SerialNumber,
102 data.Metadata.DeviceID,
103 data.Metadata.Context.InterfaceID,
104 data.Metadata.Context.PonID,
105 data.Metadata.Context.PortNumber,
106 data.Metadata.Title,
107 ).Set(data.Metrics.RxPackets)
108
109 txErrorPacketsTotal.WithLabelValues(
110 data.Metadata.LogicalDeviceID,
111 data.Metadata.SerialNumber,
112 data.Metadata.DeviceID,
113 data.Metadata.Context.InterfaceID,
114 data.Metadata.Context.PonID,
115 data.Metadata.Context.PortNumber,
116 data.Metadata.Title,
117 ).Set(data.Metrics.TxErrorPackets)
118
119 rxErrorPacketsTotal.WithLabelValues(
120 data.Metadata.LogicalDeviceID,
121 data.Metadata.SerialNumber,
122 data.Metadata.DeviceID,
123 data.Metadata.Context.InterfaceID,
124 data.Metadata.Context.PonID,
125 data.Metadata.Context.PortNumber,
126 data.Metadata.Title,
127 ).Set(data.Metrics.RxErrorPackets)
128
129 // TODO add metrics for:
130 // TxBcastPackets
131 // TxUnicastPackets
132 // TxMulticastPackets
133 // RxBcastPackets
134 // RxMulticastPackets
135
136 }
137}