Skip to content

Commit

Permalink
Expose administrative state of network interfaces as 'adminstate'. (p…
Browse files Browse the repository at this point in the history
…rometheus#2515)

Signed-off-by: Maximilian Wilhelm <max@sdn.clinic>
  • Loading branch information
BarbarossaTM authored and oblitorum committed Apr 9, 2024
1 parent a0c5517 commit 97437cd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
4 changes: 2 additions & 2 deletions collector/fixtures/e2e-64k-page-output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2411,8 +2411,8 @@ node_network_iface_link_mode{device="bond0"} 1
node_network_iface_link_mode{device="eth0"} 1
# HELP node_network_info Non-numeric data from /sys/class/net/<iface>, value is always 1.
# TYPE node_network_info gauge
node_network_info{address="01:01:01:01:01:01",broadcast="ff:ff:ff:ff:ff:ff",device="bond0",duplex="full",ifalias="",operstate="up"} 1
node_network_info{address="01:01:01:01:01:01",broadcast="ff:ff:ff:ff:ff:ff",device="eth0",duplex="full",ifalias="",operstate="up"} 1
node_network_info{address="01:01:01:01:01:01",adminstate="up",broadcast="ff:ff:ff:ff:ff:ff",device="bond0",duplex="full",ifalias="",operstate="up"} 1
node_network_info{address="01:01:01:01:01:01",adminstate="up",broadcast="ff:ff:ff:ff:ff:ff",device="eth0",duplex="full",ifalias="",operstate="up"} 1
# HELP node_network_mtu_bytes Network device property: mtu_bytes
# TYPE node_network_mtu_bytes gauge
node_network_mtu_bytes{device="bond0"} 1500
Expand Down
4 changes: 2 additions & 2 deletions collector/fixtures/e2e-output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2702,8 +2702,8 @@ node_network_iface_link_mode{device="bond0"} 1
node_network_iface_link_mode{device="eth0"} 1
# HELP node_network_info Non-numeric data from /sys/class/net/<iface>, value is always 1.
# TYPE node_network_info gauge
node_network_info{address="01:01:01:01:01:01",broadcast="ff:ff:ff:ff:ff:ff",device="bond0",duplex="full",ifalias="",operstate="up"} 1
node_network_info{address="01:01:01:01:01:01",broadcast="ff:ff:ff:ff:ff:ff",device="eth0",duplex="full",ifalias="",operstate="up"} 1
node_network_info{address="01:01:01:01:01:01",adminstate="up",broadcast="ff:ff:ff:ff:ff:ff",device="bond0",duplex="full",ifalias="",operstate="up"} 1
node_network_info{address="01:01:01:01:01:01",adminstate="up",broadcast="ff:ff:ff:ff:ff:ff",device="eth0",duplex="full",ifalias="",operstate="up"} 1
# HELP node_network_mtu_bytes Network device property: mtu_bytes
# TYPE node_network_mtu_bytes gauge
node_network_mtu_bytes{device="bond0"} 1500
Expand Down
17 changes: 15 additions & 2 deletions collector/netclass_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package collector
import (
"errors"
"fmt"
"net"
"os"
"regexp"

Expand Down Expand Up @@ -96,12 +97,12 @@ func (c *netClassCollector) netClassSysfsUpdate(ch chan<- prometheus.Metric) err
infoDesc := prometheus.NewDesc(
prometheus.BuildFQName(namespace, c.subsystem, "info"),
"Non-numeric data from /sys/class/net/<iface>, value is always 1.",
[]string{"device", "address", "broadcast", "duplex", "operstate", "ifalias"},
[]string{"device", "address", "broadcast", "duplex", "operstate", "adminstate", "ifalias"},
nil,
)
infoValue := 1.0

ch <- prometheus.MustNewConstMetric(infoDesc, prometheus.GaugeValue, infoValue, ifaceInfo.Name, ifaceInfo.Address, ifaceInfo.Broadcast, ifaceInfo.Duplex, ifaceInfo.OperState, ifaceInfo.IfAlias)
ch <- prometheus.MustNewConstMetric(infoDesc, prometheus.GaugeValue, infoValue, ifaceInfo.Name, ifaceInfo.Address, ifaceInfo.Broadcast, ifaceInfo.Duplex, ifaceInfo.OperState, getAdminState(ifaceInfo.Flags), ifaceInfo.IfAlias)

pushMetric(ch, c.getFieldDesc("address_assign_type"), "address_assign_type", ifaceInfo.AddrAssignType, prometheus.GaugeValue, ifaceInfo.Name)
pushMetric(ch, c.getFieldDesc("carrier"), "carrier", ifaceInfo.Carrier, prometheus.GaugeValue, ifaceInfo.Name)
Expand Down Expand Up @@ -170,3 +171,15 @@ func (c *netClassCollector) getNetClassInfo() (sysfs.NetClass, error) {

return netClass, nil
}

func getAdminState(flags *int64) string {
if flags == nil {
return "unknown"
}

if *flags&int64(net.FlagUp) == 1 {
return "up"
}

return "down"
}

0 comments on commit 97437cd

Please sign in to comment.