mirror of
https://github.com/prometheus/node_exporter.git
synced 2025-01-13 06:48:05 -08:00
Expose administrative state of network interfaces as 'adminstate'. (#2515)
Signed-off-by: Maximilian Wilhelm <max@sdn.clinic>
This commit is contained in:
parent
a7f92756d3
commit
c8129fadd6
|
@ -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
|
||||
|
|
|
@ -2433,8 +2433,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
|
||||
|
|
|
@ -19,6 +19,7 @@ package collector
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"regexp"
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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"
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue