Skip to content

Commit 31f124a

Browse files
author
Guillaume Espanel
committed
Fix ethtool returning 0 for sanitized metrics
The ethtool_linux looks for ethtool stats with their sanitized name which might be different from the name provisioned by ethtool. This caused node-exporter to return a 0-value for sanitized metrics. This patch works-around the missing key by copying ethtool stats to their sanitized name. Signed-off-by: Guillaume Espanel <[email protected]>
1 parent 43fb05c commit 31f124a

File tree

3 files changed

+7
-0
lines changed

3 files changed

+7
-0
lines changed

collector/ethtool_linux.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,8 @@ func (c *ethtoolCollector) Update(ch chan<- prometheus.Metric) error {
467467
metricFQNames[metricFQName] = ""
468468
} else {
469469
metricFQNames[metricFQName] = metricName
470+
// Later we'll go look for the stat with the "sanitized" metric name, so we can copy it there already
471+
stats[metricName] = stats[metric]
470472
}
471473
}
472474

collector/ethtool_linux_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ func NewEthtoolTestCollector(logger *slog.Logger) (Collector, error) {
269269

270270
func TestBuildEthtoolFQName(t *testing.T) {
271271
testcases := map[string]string{
272+
"port.rx_errors": "node_ethtool_port_received_errors",
272273
"rx_errors": "node_ethtool_received_errors",
273274
"Queue[0] AllocFails": "node_ethtool_queue_0_allocfails",
274275
"Tx LPI entry count": "node_ethtool_transmitted_lpi_entry_count",
@@ -292,6 +293,9 @@ node_ethtool_align_errors{device="eth0"} 0
292293
# HELP node_ethtool_info A metric with a constant '1' value labeled by bus_info, device, driver, expansion_rom_version, firmware_version, version.
293294
# TYPE node_ethtool_info gauge
294295
node_ethtool_info{bus_info="0000:00:1f.6",device="eth0",driver="e1000e",expansion_rom_version="",firmware_version="0.5-4",version="5.11.0-22-generic"} 1
296+
# HELP node_ethtool_port_received_dropped Network interface port_rx_dropped
297+
# TYPE node_ethtool_port_received_dropped untyped
298+
node_ethtool_port_received_dropped{device="eth0"} 12028
295299
# HELP node_ethtool_received_broadcast Network interface rx_broadcast
296300
# TYPE node_ethtool_received_broadcast untyped
297301
node_ethtool_received_broadcast{device="eth0"} 5792

collector/fixtures/ethtool/eth0/statistics

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ NIC statistics:
44
rx_packets: 1260062
55
tx_errors: 0
66
rx_errors: 0
7+
port.rx_dropped: 12028
78
rx_missed: 401
89
align_errors: 0
910
tx_single_collisions: 0

0 commit comments

Comments
 (0)