From e0d6d1185988bb1eb33779539399dd0e6cab0238 Mon Sep 17 00:00:00 2001 From: Paul Gier Date: Thu, 7 Feb 2019 08:59:32 -0600 Subject: [PATCH] netclass_linux: remove varying labels from the 'up' metric (#1243) * netclass_linux: remove varying labels from the 'up' metric This moves the variable label values such as 'operstate' out of the 'network_up' metric and into a separate metric called '_info'. This allows the 'up' metric to remain continous over state changes. Fixes #1236 Signed-off-by: Paul Gier --- CHANGELOG.md | 2 ++ collector/fixtures/e2e-64k-page-output.txt | 7 +++++-- collector/fixtures/e2e-output.txt | 7 +++++-- collector/netclass_linux.go | 18 ++++++++++++++---- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d95bc2a..77f84cbc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ * Renamed `interface` label to `device` in netclass collector for consistency with other network metrics #1224 * The cpufreq metrics now separate the `cpufreq` and `scaling` data based on what the driver provides. #1248 +* The labels for the network_up metric have changed, see issue #1236 ### Changes @@ -15,6 +16,7 @@ * [CHANGE] Add a limit to the number of in-flight requests #1166 * [CHANGE] Add separate cpufreq and scaling metrics #1248 * [ENHANCEMENT] Add Infiniband counters #1120 +* [ENHANCEMENT] Move network_up labels into new metric network_info #1236 * [FEATURE] Add a flag to disable exporter metrics #1148 * [FEATURE] Add kstat-based Solaris metrics for boottime, cpu and zfs collectors #1197 * [FEATURE] Add uname collector for FreeBSD #1239 diff --git a/collector/fixtures/e2e-64k-page-output.txt b/collector/fixtures/e2e-64k-page-output.txt index 7e61462e..aa96e911 100644 --- a/collector/fixtures/e2e-64k-page-output.txt +++ b/collector/fixtures/e2e-64k-page-output.txt @@ -1835,6 +1835,9 @@ node_network_iface_link{interface="eth0"} 2 # HELP node_network_iface_link_mode iface_link_mode value of /sys/class/net/. # TYPE node_network_iface_link_mode gauge node_network_iface_link_mode{interface="eth0"} 1 +# HELP node_network_info Non-numeric data from /sys/class/net/, 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="eth0",duplex="full",ifalias="",operstate="up"} 1 # HELP node_network_mtu_bytes mtu_bytes value of /sys/class/net/. # TYPE node_network_mtu_bytes gauge node_network_mtu_bytes{interface="eth0"} 1500 @@ -2045,9 +2048,9 @@ node_network_transmit_packets_total{device="💩0"} 304261 # HELP node_network_transmit_queue_length transmit_queue_length value of /sys/class/net/. # TYPE node_network_transmit_queue_length gauge node_network_transmit_queue_length{interface="eth0"} 1000 -# HELP node_network_up Valid operstate for interface. +# HELP node_network_up Value is 1 if operstate is 'up', 0 otherwise. # TYPE node_network_up gauge -node_network_up{address="01:01:01:01:01:01",broadcast="ff:ff:ff:ff:ff:ff",duplex="full",ifalias="",interface="eth0",operstate="up"} 1 +node_network_up{device="eth0"} 1 # HELP node_nf_conntrack_entries Number of currently allocated flow entries for connection tracking. # TYPE node_nf_conntrack_entries gauge node_nf_conntrack_entries 123 diff --git a/collector/fixtures/e2e-output.txt b/collector/fixtures/e2e-output.txt index 2f9e0974..d278833c 100644 --- a/collector/fixtures/e2e-output.txt +++ b/collector/fixtures/e2e-output.txt @@ -1835,6 +1835,9 @@ node_network_iface_link{device="eth0"} 2 # HELP node_network_iface_link_mode iface_link_mode value of /sys/class/net/. # TYPE node_network_iface_link_mode gauge node_network_iface_link_mode{device="eth0"} 1 +# HELP node_network_info Non-numeric data from /sys/class/net/, 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="eth0",duplex="full",ifalias="",operstate="up"} 1 # HELP node_network_mtu_bytes mtu_bytes value of /sys/class/net/. # TYPE node_network_mtu_bytes gauge node_network_mtu_bytes{device="eth0"} 1500 @@ -2045,9 +2048,9 @@ node_network_transmit_packets_total{device="💩0"} 304261 # HELP node_network_transmit_queue_length transmit_queue_length value of /sys/class/net/. # TYPE node_network_transmit_queue_length gauge node_network_transmit_queue_length{device="eth0"} 1000 -# HELP node_network_up Valid operstate for device. +# HELP node_network_up Value is 1 if operstate is 'up', 0 otherwise. # TYPE node_network_up gauge -node_network_up{address="01:01:01:01:01:01",broadcast="ff:ff:ff:ff:ff:ff",device="eth0",duplex="full",ifalias="",operstate="up"} 1 +node_network_up{device="eth0"} 1 # HELP node_nf_conntrack_entries Number of currently allocated flow entries for connection tracking. # TYPE node_nf_conntrack_entries gauge node_nf_conntrack_entries 123 diff --git a/collector/netclass_linux.go b/collector/netclass_linux.go index fffbd848..d70db586 100644 --- a/collector/netclass_linux.go +++ b/collector/netclass_linux.go @@ -22,7 +22,7 @@ import ( "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/procfs/sysfs" - "gopkg.in/alecthomas/kingpin.v2" + kingpin "gopkg.in/alecthomas/kingpin.v2" ) var ( @@ -57,8 +57,8 @@ func (c *netClassCollector) Update(ch chan<- prometheus.Metric) error { for _, ifaceInfo := range netClass { upDesc := prometheus.NewDesc( prometheus.BuildFQName(namespace, c.subsystem, "up"), - "Valid operstate for device.", - []string{"device", "address", "broadcast", "duplex", "operstate", "ifalias"}, + "Value is 1 if operstate is 'up', 0 otherwise.", + []string{"device"}, nil, ) upValue := 0.0 @@ -66,7 +66,17 @@ func (c *netClassCollector) Update(ch chan<- prometheus.Metric) error { upValue = 1.0 } - ch <- prometheus.MustNewConstMetric(upDesc, prometheus.GaugeValue, upValue, ifaceInfo.Name, ifaceInfo.Address, ifaceInfo.Broadcast, ifaceInfo.Duplex, ifaceInfo.OperState, ifaceInfo.IfAlias) + ch <- prometheus.MustNewConstMetric(upDesc, prometheus.GaugeValue, upValue, ifaceInfo.Name) + + infoDesc := prometheus.NewDesc( + prometheus.BuildFQName(namespace, c.subsystem, "info"), + "Non-numeric data from /sys/class/net/, value is always 1.", + []string{"device", "address", "broadcast", "duplex", "operstate", "ifalias"}, + nil, + ) + infoValue := 1.0 + + ch <- prometheus.MustNewConstMetric(infoDesc, prometheus.GaugeValue, infoValue, ifaceInfo.Name, ifaceInfo.Address, ifaceInfo.Broadcast, ifaceInfo.Duplex, ifaceInfo.OperState, ifaceInfo.IfAlias) if ifaceInfo.AddrAssignType != nil { pushMetric(ch, c.subsystem, "address_assign_type", *ifaceInfo.AddrAssignType, ifaceInfo.Name, prometheus.GaugeValue)