forked from prometheus-community/fortigate_exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsystem_interface.go
More file actions
114 lines (107 loc) · 4.44 KB
/
Copy pathsystem_interface.go
File metadata and controls
114 lines (107 loc) · 4.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// Copyright The Prometheus Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package probe
import (
"log"
"strconv"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus-community/fortigate_exporter/pkg/fortigatehttpclient"
)
func probeSystemInterface(c fortigatehttpclient.FortiHTTP, _ *TargetMetadata) ([]prometheus.Metric, bool) {
var (
mLink = prometheus.NewDesc(
"fortigate_interface_link_up",
"Whether the link is up or not (not taking into account admin status)",
[]string{"vdom", "name", "vlanid", "alias", "parent"}, nil,
)
mSpeed = prometheus.NewDesc(
"fortigate_interface_speed_bps",
"Speed negotiated on the port in bits/s",
[]string{"vdom", "name", "vlanid", "alias", "parent"}, nil,
)
mTxPkts = prometheus.NewDesc(
"fortigate_interface_transmit_packets_total",
"Number of packets transmitted on the interface",
[]string{"vdom", "name", "vlanid", "alias", "parent"}, nil,
)
mRxPkts = prometheus.NewDesc(
"fortigate_interface_receive_packets_total",
"Number of packets received on the interface",
[]string{"vdom", "name", "vlanid", "alias", "parent"}, nil,
)
mTxB = prometheus.NewDesc(
"fortigate_interface_transmit_bytes_total",
"Number of bytes transmitted on the interface",
[]string{"vdom", "name", "vlanid", "alias", "parent"}, nil,
)
mRxB = prometheus.NewDesc(
"fortigate_interface_receive_bytes_total",
"Number of bytes received on the interface",
[]string{"vdom", "name", "vlanid", "alias", "parent"}, nil,
)
mTxErr = prometheus.NewDesc(
"fortigate_interface_transmit_errors_total",
"Number of transmission errors detected on the interface",
[]string{"vdom", "name", "vlanid", "alias", "parent"}, nil,
)
mRxErr = prometheus.NewDesc(
"fortigate_interface_receive_errors_total",
"Number of reception errors detected on the interface",
[]string{"vdom", "name", "vlanid", "alias", "parent"}, nil,
)
)
type ifResult struct {
ID string
Name string
Alias string
Link bool
Speed float64
Duplex float64
TxPackets float64 `json:"tx_packets"`
RxPackets float64 `json:"rx_packets"`
TxBytes float64 `json:"tx_bytes"`
RxBytes float64 `json:"rx_bytes"`
TxErrors float64 `json:"tx_errors"`
RxErrors float64 `json:"rx_errors"`
VlanID int `json:"vlanid"`
Interface string
}
type ifResponse struct {
Results map[string]ifResult
VDOM string
}
var r []ifResponse
if err := c.Get("api/v2/monitor/system/interface/select", "vdom=*&include_vlan=true&include_aggregate=true", &r); err != nil {
log.Printf("Error: %v", err)
return nil, false
}
m := []prometheus.Metric{}
for _, v := range r {
for _, ir := range v.Results {
linkf := 0.0
if ir.Link {
linkf = 1.0
}
vlanString := strconv.Itoa(ir.VlanID)
m = append(m, prometheus.MustNewConstMetric(mLink, prometheus.GaugeValue, linkf, v.VDOM, ir.Name, vlanString, ir.Alias, ir.Interface))
m = append(m, prometheus.MustNewConstMetric(mSpeed, prometheus.GaugeValue, ir.Speed*1000*1000, v.VDOM, ir.Name, vlanString, ir.Alias, ir.Interface))
m = append(m, prometheus.MustNewConstMetric(mTxPkts, prometheus.CounterValue, ir.TxPackets, v.VDOM, ir.Name, vlanString, ir.Alias, ir.Interface))
m = append(m, prometheus.MustNewConstMetric(mRxPkts, prometheus.CounterValue, ir.RxPackets, v.VDOM, ir.Name, vlanString, ir.Alias, ir.Interface))
m = append(m, prometheus.MustNewConstMetric(mTxB, prometheus.CounterValue, ir.TxBytes, v.VDOM, ir.Name, vlanString, ir.Alias, ir.Interface))
m = append(m, prometheus.MustNewConstMetric(mRxB, prometheus.CounterValue, ir.RxBytes, v.VDOM, ir.Name, vlanString, ir.Alias, ir.Interface))
m = append(m, prometheus.MustNewConstMetric(mTxErr, prometheus.CounterValue, ir.TxErrors, v.VDOM, ir.Name, vlanString, ir.Alias, ir.Interface))
m = append(m, prometheus.MustNewConstMetric(mRxErr, prometheus.CounterValue, ir.RxErrors, v.VDOM, ir.Name, vlanString, ir.Alias, ir.Interface))
}
}
return m, true
}