Expose administrative state of network interfaces as 'adminstate'. (#2515)

Signed-off-by: Maximilian Wilhelm <max@sdn.clinic>
This commit is contained in:
Maximilian Wilhelm 2023-05-02 15:25:05 +02:00 committed by GitHub
parent a7f92756d3
commit c8129fadd6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 6 deletions

View file

@ -2411,8 +2411,8 @@ node_network_iface_link_mode{device="bond0"} 1
node_network_iface_link_mode{device="eth0"} 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. # HELP node_network_info Non-numeric data from /sys/class/net/<iface>, value is always 1.
# TYPE node_network_info gauge # 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",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",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="eth0",duplex="full",ifalias="",operstate="up"} 1
# HELP node_network_mtu_bytes Network device property: mtu_bytes # HELP node_network_mtu_bytes Network device property: mtu_bytes
# TYPE node_network_mtu_bytes gauge # TYPE node_network_mtu_bytes gauge
node_network_mtu_bytes{device="bond0"} 1500 node_network_mtu_bytes{device="bond0"} 1500

View file

@ -2433,8 +2433,8 @@ node_network_iface_link_mode{device="bond0"} 1
node_network_iface_link_mode{device="eth0"} 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. # HELP node_network_info Non-numeric data from /sys/class/net/<iface>, value is always 1.
# TYPE node_network_info gauge # 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",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",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="eth0",duplex="full",ifalias="",operstate="up"} 1
# HELP node_network_mtu_bytes Network device property: mtu_bytes # HELP node_network_mtu_bytes Network device property: mtu_bytes
# TYPE node_network_mtu_bytes gauge # TYPE node_network_mtu_bytes gauge
node_network_mtu_bytes{device="bond0"} 1500 node_network_mtu_bytes{device="bond0"} 1500

View file

@ -19,6 +19,7 @@ package collector
import ( import (
"errors" "errors"
"fmt" "fmt"
"net"
"os" "os"
"regexp" "regexp"
@ -96,12 +97,12 @@ func (c *netClassCollector) netClassSysfsUpdate(ch chan<- prometheus.Metric) err
infoDesc := prometheus.NewDesc( infoDesc := prometheus.NewDesc(
prometheus.BuildFQName(namespace, c.subsystem, "info"), prometheus.BuildFQName(namespace, c.subsystem, "info"),
"Non-numeric data from /sys/class/net/<iface>, value is always 1.", "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, nil,
) )
infoValue := 1.0 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("address_assign_type"), "address_assign_type", ifaceInfo.AddrAssignType, prometheus.GaugeValue, ifaceInfo.Name)
pushMetric(ch, c.getFieldDesc("carrier"), "carrier", ifaceInfo.Carrier, prometheus.GaugeValue, ifaceInfo.Name) pushMetric(ch, c.getFieldDesc("carrier"), "carrier", ifaceInfo.Carrier, prometheus.GaugeValue, ifaceInfo.Name)
@ -170,3 +171,15 @@ func (c *netClassCollector) getNetClassInfo() (sysfs.NetClass, error) {
return netClass, nil return netClass, nil
} }
func getAdminState(flags *int64) string {
if flags == nil {
return "unknown"
}
if *flags&int64(net.FlagUp) == 1 {
return "up"
}
return "down"
}