Skip to content

Commit

Permalink
feat(probe): Add vlanid label to interface metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
Jad Seifeddine authored and Jad Seifeddine committed Feb 9, 2024
1 parent 2aaf029 commit 3714c6d
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions pkg/probe/system_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package probe

import (
"log"

"strconv"
"github.com/bluecmd/fortigate_exporter/pkg/http"
"github.com/prometheus/client_golang/prometheus"
)
Expand All @@ -12,42 +12,42 @@ func probeSystemInterface(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus.
mLink = prometheus.NewDesc(
"fortigate_interface_link_up",
"Whether the link is up or not (not taking into account admin status)",
[]string{"vdom", "name", "alias", "parent"}, nil,
[]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", "alias", "parent"}, nil,
[]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", "alias", "parent"}, nil,
[]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", "alias", "parent"}, nil,
[]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", "alias", "parent"}, nil,
[]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", "alias", "parent"}, nil,
[]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", "alias", "parent"}, nil,
[]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", "alias", "parent"}, nil,
[]string{"vdom", "name", "vlanid", "alias", "parent"}, nil,
)
)

Expand All @@ -64,6 +64,7 @@ func probeSystemInterface(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus.
RxBytes float64 `json:"rx_bytes"`
TxErrors float64 `json:"tx_errors"`
RxErrors float64 `json:"rx_errors"`
VlanID int `json:"vlanid"`
Interface string
}
type ifResponse struct {
Expand All @@ -83,14 +84,15 @@ func probeSystemInterface(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus.
if ir.Link {
linkf = 1.0
}
m = append(m, prometheus.MustNewConstMetric(mLink, prometheus.GaugeValue, linkf, v.VDOM, ir.Name, ir.Alias, ir.Interface))
m = append(m, prometheus.MustNewConstMetric(mSpeed, prometheus.GaugeValue, ir.Speed*1000*1000, v.VDOM, ir.Name, ir.Alias, ir.Interface))
m = append(m, prometheus.MustNewConstMetric(mTxPkts, prometheus.CounterValue, ir.TxPackets, v.VDOM, ir.Name, ir.Alias, ir.Interface))
m = append(m, prometheus.MustNewConstMetric(mRxPkts, prometheus.CounterValue, ir.RxPackets, v.VDOM, ir.Name, ir.Alias, ir.Interface))
m = append(m, prometheus.MustNewConstMetric(mTxB, prometheus.CounterValue, ir.TxBytes, v.VDOM, ir.Name, ir.Alias, ir.Interface))
m = append(m, prometheus.MustNewConstMetric(mRxB, prometheus.CounterValue, ir.RxBytes, v.VDOM, ir.Name, ir.Alias, ir.Interface))
m = append(m, prometheus.MustNewConstMetric(mTxErr, prometheus.CounterValue, ir.TxErrors, v.VDOM, ir.Name, ir.Alias, ir.Interface))
m = append(m, prometheus.MustNewConstMetric(mRxErr, prometheus.CounterValue, ir.RxErrors, v.VDOM, ir.Name, ir.Alias, ir.Interface))
vlan_string := strconv.Itoa(ir.VlanID)
m = append(m, prometheus.MustNewConstMetric(mLink, prometheus.GaugeValue, linkf, v.VDOM, ir.Name, vlan_string, ir.Alias, ir.Interface))
m = append(m, prometheus.MustNewConstMetric(mSpeed, prometheus.GaugeValue, ir.Speed*1000*1000, v.VDOM, ir.Name, vlan_string, ir.Alias, ir.Interface))
m = append(m, prometheus.MustNewConstMetric(mTxPkts, prometheus.CounterValue, ir.TxPackets, v.VDOM, ir.Name, vlan_string, ir.Alias, ir.Interface))
m = append(m, prometheus.MustNewConstMetric(mRxPkts, prometheus.CounterValue, ir.RxPackets, v.VDOM, ir.Name, vlan_string, ir.Alias, ir.Interface))
m = append(m, prometheus.MustNewConstMetric(mTxB, prometheus.CounterValue, ir.TxBytes, v.VDOM, ir.Name, vlan_string, ir.Alias, ir.Interface))
m = append(m, prometheus.MustNewConstMetric(mRxB, prometheus.CounterValue, ir.RxBytes, v.VDOM, ir.Name, vlan_string, ir.Alias, ir.Interface))
m = append(m, prometheus.MustNewConstMetric(mTxErr, prometheus.CounterValue, ir.TxErrors, v.VDOM, ir.Name, vlan_string, ir.Alias, ir.Interface))
m = append(m, prometheus.MustNewConstMetric(mRxErr, prometheus.CounterValue, ir.RxErrors, v.VDOM, ir.Name, vlan_string, ir.Alias, ir.Interface))
}
}
return m, true
Expand Down

0 comments on commit 3714c6d

Please sign in to comment.