{"record":{"id":"4d6db2a1c2ae46dd","repo":"prometheus/node_exporter","slug":"couldn-t-get-netdev-labels-w","errorCode":null,"errorMessage":"couldn't get netdev labels: %w","messagePattern":"couldn't get netdev labels: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"collector/netdev_common.go","lineNumber":117,"sourceCode":"\t\t\tprometheus.BuildFQName(namespace, c.subsystem, key+\"_total\"),\n\t\t\tfmt.Sprintf(\"Network device statistic %s.\", key),\n\t\t\tlabels,\n\t\t\tnil,\n\t\t)\n\t}\n\n\treturn c.metricDescs[key]\n}\n\nfunc (c *netDevCollector) Update(ch chan<- prometheus.Metric) error {\n\tnetDev, err := getNetDevStats(&c.deviceFilter, c.logger)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"couldn't get netstats: %w\", err)\n\t}\n\n\tnetDevLabels, err := getNetDevLabels()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"couldn't get netdev labels: %w\", err)\n\t}\n\n\tfor dev, devStats := range netDev {\n\t\tif !*netdevDetailedMetrics {\n\t\t\tlegacy(devStats)\n\t\t}\n\n\t\tlabels := []string{\"device\"}\n\t\tlabelValues := []string{dev}\n\t\tif devLabels, exists := netDevLabels[dev]; exists {\n\t\t\tfor labelName, labelValue := range devLabels {\n\t\t\t\tlabels = append(labels, labelName)\n\t\t\t\tlabelValues = append(labelValues, labelValue)\n\t\t\t}\n\t\t}\n\n\t\tfor key, value := range devStats {\n\t\t\tdesc := c.metricDesc(key, labels)","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/prometheus/node_exporter/blob/17ddd77c59ba27e1508e9f7894b1e55b44d6aed3/collector/netdev_common.go#L99-L135","documentation":"After netdev stats are fetched, Update calls getNetDevLabels() to build the per-device label set (e.g. device speed/duplex annotations read from sysfs). A failure there is wrapped as 'couldn't get netdev labels' and the netdev scrape fails even though the raw stats were already collected successfully.","triggerScenarios":"getNetDevLabels() returns an error — on Linux it walks /sys/class/net/<dev> to read label attributes; it fails when /sys is missing/unmounted, unreadable due to permissions, or a sysfs read returns an I/O error mid-walk.","commonSituations":"Containers without /sys bind-mounted (very common misconfiguration); sysfs read race when an interface is hot-removed between stats and label collection; running node_exporter as a non-root user with restrictive LSM rules.","solutions":["Mount sysfs read-only into the container: -v /sys:/host/sys:ro and pass --path.sysfs=/host/sys.","Verify /sys/class/net/<device> files exist and are readable by the exporter's user.","Look at the wrapped inner error for the exact sysfs path that failed.","Update node_exporter: label-collection failures may be downgraded to per-device skips in newer releases.","If labels are not needed, confirm whether your version supports disabling the label enrichment path via flags."],"exampleFix":"// before: exporter inside container without sysfs\n// node_network_info labels unavailable, scrape fails\n// after: run with sysfs mounted\ndocker run -v /proc:/host/proc:ro -v /sys:/host/sys:ro \\\n  prom/node-exporter --path.procfs=/host/proc --path.sysfs=/host/sys","handlingStrategy":"fallback","validationCode":"// preflight: sysfs labels source present\nif _, err := os.Stat(\"/sys/class/net\"); err != nil {\n\t// labels unavailable; netdev will fail on getNetDevLabels\n\tlog.Printf(\"sysfs unavailable: %v\", err)\n}","typeGuard":null,"tryCatchPattern":"err := collector.Update(ch)\nif err != nil && strings.Contains(err.Error(), \"couldn't get netdev labels\") {\n\tlogger.Warn(\"netdev labels unavailable; proceeding without info labels\", \"cause\", err)\n}","preventionTips":["Mount /sys:ro in containers and set --path.sysfs correctly","Keep exporter user permissions permissive enough for sysfs reads","Upgrade node_exporter so label failures degrade to warnings","Track this error in logs distinct from the netstats error to isolate sysfs issues"],"tags":["network","sysfs","metrics"],"backgroundTag":"file-read-failed","analyzedSha":"17ddd77c59ba27e1508e9f7894b1e55b44d6aed3","analyzedAt":"2026-09-07T17:54:06.211Z","contentChangedAt":"2026-09-07T17:54:06.211Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}