Skip to content

Commit c6c25c0

Browse files
committed
feat(probe): Add vlanid label to interface metrics
Signed-off-by: Jad Seifeddine <jad.seifeddine@icloud.com>
1 parent b6300ce commit c6c25c0

1 file changed

Lines changed: 20 additions & 18 deletions

File tree

pkg/probe/system_interface.go

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,53 +15,53 @@ package probe
1515

1616
import (
1717
"log"
18-
19-
"github.com/prometheus/client_golang/prometheus"
18+
"strconv"
2019

2120
"github.com/prometheus-community/fortigate_exporter/pkg/fortigatehttpclient"
21+
"github.com/prometheus/client_golang/prometheus"
2222
)
2323

2424
func probeSystemInterface(c fortigatehttpclient.FortiHTTP, _ *TargetMetadata) ([]prometheus.Metric, bool) {
2525
var (
2626
mLink = prometheus.NewDesc(
2727
"fortigate_interface_link_up",
2828
"Whether the link is up or not (not taking into account admin status)",
29-
[]string{"vdom", "name", "alias", "parent"}, nil,
29+
[]string{"vdom", "name", "vlanid", "alias", "parent"}, nil,
3030
)
3131
mSpeed = prometheus.NewDesc(
3232
"fortigate_interface_speed_bps",
3333
"Speed negotiated on the port in bits/s",
34-
[]string{"vdom", "name", "alias", "parent"}, nil,
34+
[]string{"vdom", "name", "vlanid", "alias", "parent"}, nil,
3535
)
3636
mTxPkts = prometheus.NewDesc(
3737
"fortigate_interface_transmit_packets_total",
3838
"Number of packets transmitted on the interface",
39-
[]string{"vdom", "name", "alias", "parent"}, nil,
39+
[]string{"vdom", "name", "vlanid", "alias", "parent"}, nil,
4040
)
4141
mRxPkts = prometheus.NewDesc(
4242
"fortigate_interface_receive_packets_total",
4343
"Number of packets received on the interface",
44-
[]string{"vdom", "name", "alias", "parent"}, nil,
44+
[]string{"vdom", "name", "vlanid", "alias", "parent"}, nil,
4545
)
4646
mTxB = prometheus.NewDesc(
4747
"fortigate_interface_transmit_bytes_total",
4848
"Number of bytes transmitted on the interface",
49-
[]string{"vdom", "name", "alias", "parent"}, nil,
49+
[]string{"vdom", "name", "vlanid", "alias", "parent"}, nil,
5050
)
5151
mRxB = prometheus.NewDesc(
5252
"fortigate_interface_receive_bytes_total",
5353
"Number of bytes received on the interface",
54-
[]string{"vdom", "name", "alias", "parent"}, nil,
54+
[]string{"vdom", "name", "vlanid", "alias", "parent"}, nil,
5555
)
5656
mTxErr = prometheus.NewDesc(
5757
"fortigate_interface_transmit_errors_total",
5858
"Number of transmission errors detected on the interface",
59-
[]string{"vdom", "name", "alias", "parent"}, nil,
59+
[]string{"vdom", "name", "vlanid", "alias", "parent"}, nil,
6060
)
6161
mRxErr = prometheus.NewDesc(
6262
"fortigate_interface_receive_errors_total",
6363
"Number of reception errors detected on the interface",
64-
[]string{"vdom", "name", "alias", "parent"}, nil,
64+
[]string{"vdom", "name", "vlanid", "alias", "parent"}, nil,
6565
)
6666
)
6767

@@ -78,6 +78,7 @@ func probeSystemInterface(c fortigatehttpclient.FortiHTTP, _ *TargetMetadata) ([
7878
RxBytes float64 `json:"rx_bytes"`
7979
TxErrors float64 `json:"tx_errors"`
8080
RxErrors float64 `json:"rx_errors"`
81+
VlanID int `json:"vlanid"`
8182
Interface string
8283
}
8384
type ifResponse struct {
@@ -97,14 +98,15 @@ func probeSystemInterface(c fortigatehttpclient.FortiHTTP, _ *TargetMetadata) ([
9798
if ir.Link {
9899
linkf = 1.0
99100
}
100-
m = append(m, prometheus.MustNewConstMetric(mLink, prometheus.GaugeValue, linkf, v.VDOM, ir.Name, ir.Alias, ir.Interface))
101-
m = append(m, prometheus.MustNewConstMetric(mSpeed, prometheus.GaugeValue, ir.Speed*1000*1000, v.VDOM, ir.Name, ir.Alias, ir.Interface))
102-
m = append(m, prometheus.MustNewConstMetric(mTxPkts, prometheus.CounterValue, ir.TxPackets, v.VDOM, ir.Name, ir.Alias, ir.Interface))
103-
m = append(m, prometheus.MustNewConstMetric(mRxPkts, prometheus.CounterValue, ir.RxPackets, v.VDOM, ir.Name, ir.Alias, ir.Interface))
104-
m = append(m, prometheus.MustNewConstMetric(mTxB, prometheus.CounterValue, ir.TxBytes, v.VDOM, ir.Name, ir.Alias, ir.Interface))
105-
m = append(m, prometheus.MustNewConstMetric(mRxB, prometheus.CounterValue, ir.RxBytes, v.VDOM, ir.Name, ir.Alias, ir.Interface))
106-
m = append(m, prometheus.MustNewConstMetric(mTxErr, prometheus.CounterValue, ir.TxErrors, v.VDOM, ir.Name, ir.Alias, ir.Interface))
107-
m = append(m, prometheus.MustNewConstMetric(mRxErr, prometheus.CounterValue, ir.RxErrors, v.VDOM, ir.Name, ir.Alias, ir.Interface))
101+
vlanString := strconv.Itoa(ir.VlanID)
102+
m = append(m, prometheus.MustNewConstMetric(mLink, prometheus.GaugeValue, linkf, v.VDOM, ir.Name, vlanString, ir.Alias, ir.Interface))
103+
m = append(m, prometheus.MustNewConstMetric(mSpeed, prometheus.GaugeValue, ir.Speed*1000*1000, v.VDOM, ir.Name, vlanString, ir.Alias, ir.Interface))
104+
m = append(m, prometheus.MustNewConstMetric(mTxPkts, prometheus.CounterValue, ir.TxPackets, v.VDOM, ir.Name, vlanString, ir.Alias, ir.Interface))
105+
m = append(m, prometheus.MustNewConstMetric(mRxPkts, prometheus.CounterValue, ir.RxPackets, v.VDOM, ir.Name, vlanString, ir.Alias, ir.Interface))
106+
m = append(m, prometheus.MustNewConstMetric(mTxB, prometheus.CounterValue, ir.TxBytes, v.VDOM, ir.Name, vlanString, ir.Alias, ir.Interface))
107+
m = append(m, prometheus.MustNewConstMetric(mRxB, prometheus.CounterValue, ir.RxBytes, v.VDOM, ir.Name, vlanString, ir.Alias, ir.Interface))
108+
m = append(m, prometheus.MustNewConstMetric(mTxErr, prometheus.CounterValue, ir.TxErrors, v.VDOM, ir.Name, vlanString, ir.Alias, ir.Interface))
109+
m = append(m, prometheus.MustNewConstMetric(mRxErr, prometheus.CounterValue, ir.RxErrors, v.VDOM, ir.Name, vlanString, ir.Alias, ir.Interface))
108110
}
109111
}
110112
return m, true

0 commit comments

Comments
 (0)