Skip to content

Commit 97437cd

Browse files
BarbarossaTMoblitorum
authored andcommitted
Expose administrative state of network interfaces as 'adminstate'. (prometheus#2515)
Signed-off-by: Maximilian Wilhelm <[email protected]>
1 parent a0c5517 commit 97437cd

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

collector/fixtures/e2e-64k-page-output.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2411,8 +2411,8 @@ node_network_iface_link_mode{device="bond0"} 1
24112411
node_network_iface_link_mode{device="eth0"} 1
24122412
# HELP node_network_info Non-numeric data from /sys/class/net/<iface>, value is always 1.
24132413
# TYPE node_network_info gauge
2414-
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
2415-
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
2414+
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
2415+
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
24162416
# HELP node_network_mtu_bytes Network device property: mtu_bytes
24172417
# TYPE node_network_mtu_bytes gauge
24182418
node_network_mtu_bytes{device="bond0"} 1500

collector/fixtures/e2e-output.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2702,8 +2702,8 @@ node_network_iface_link_mode{device="bond0"} 1
27022702
node_network_iface_link_mode{device="eth0"} 1
27032703
# HELP node_network_info Non-numeric data from /sys/class/net/<iface>, value is always 1.
27042704
# TYPE node_network_info gauge
2705-
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
2706-
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
2705+
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
2706+
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
27072707
# HELP node_network_mtu_bytes Network device property: mtu_bytes
27082708
# TYPE node_network_mtu_bytes gauge
27092709
node_network_mtu_bytes{device="bond0"} 1500

collector/netclass_linux.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package collector
1919
import (
2020
"errors"
2121
"fmt"
22+
"net"
2223
"os"
2324
"regexp"
2425

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

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

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

171172
return netClass, nil
172173
}
174+
175+
func getAdminState(flags *int64) string {
176+
if flags == nil {
177+
return "unknown"
178+
}
179+
180+
if *flags&int64(net.FlagUp) == 1 {
181+
return "up"
182+
}
183+
184+
return "down"
185+
}

0 commit comments

Comments
 (0)