Skip to content

Commit 45eb59d

Browse files
quatreGuillaume Espanel
andauthored
Fix ethtool returning 0 for sanitized metrics (#3335)
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 another map under their sanitized name. Signed-off-by: Guillaume Espanel <[email protected]> Co-authored-by: Guillaume Espanel <[email protected]>
1 parent 67ebd4c commit 45eb59d

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

collector/ethtool_linux.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ func (c *ethtoolCollector) Update(ch chan<- prometheus.Metric) error {
453453

454454
// Sanitizing the metric names can lead to duplicate metric names. Therefore check for clashes beforehand.
455455
metricFQNames := make(map[string]string)
456+
renamedStats := make(map[string]uint64, len(stats))
456457
for metric := range stats {
457458
metricName := SanitizeMetricName(metric)
458459
if !c.metricsPattern.MatchString(metricName) {
@@ -467,6 +468,8 @@ func (c *ethtoolCollector) Update(ch chan<- prometheus.Metric) error {
467468
metricFQNames[metricFQName] = ""
468469
} else {
469470
metricFQNames[metricFQName] = metricName
471+
// Later we'll go look for the stat with the "sanitized" metric name, so we can copy it there already
472+
renamedStats[metricName] = stats[metric]
470473
}
471474
}
472475

@@ -484,7 +487,7 @@ func (c *ethtoolCollector) Update(ch chan<- prometheus.Metric) error {
484487
continue
485488
}
486489

487-
val := stats[metric]
490+
val := renamedStats[metric]
488491

489492
// Check to see if this metric exists; if not then create it and store it in c.entries.
490493
entry := c.entryWithCreate(metric, metricFQName)

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)