{"record":{"id":"bc99eae60d24bbe2","repo":"prometheus/node_exporter","slug":"couldn-t-get-netstats-w-bc99ea","errorCode":null,"errorMessage":"couldn't get netstats: %w","messagePattern":"couldn't get netstats: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"collector/netstat_linux.go","lineNumber":82,"sourceCode":"\t// Network statistics in /proc/net are network namespace local. Reading\n\t// them via the current process' /proc/self/net keeps the same semantics\n\t// while allowing the use of the procfs parsers.\n\tproc, err := fs.Self()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to open /proc/self: %w\", err)\n\t}\n\n\treturn &netStatCollector{\n\t\tproc:         proc,\n\t\tfieldPattern: pattern,\n\t\tlogger:       logger,\n\t}, nil\n}\n\nfunc (c *netStatCollector) Update(ch chan<- prometheus.Metric) error {\n\tnetStats, err := c.proc.Netstat()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"couldn't get netstats: %w\", err)\n\t}\n\tsnmpStats, err := c.proc.Snmp()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"couldn't get SNMP stats: %w\", err)\n\t}\n\tsnmp6Stats, err := c.proc.Snmp6()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"couldn't get SNMP6 stats: %w\", err)\n\t}\n\n\tc.emitStruct(ch, netStats.TcpExt)\n\tc.emitStruct(ch, netStats.IpExt)\n\tc.emitStruct(ch, snmpStats.Ip)\n\tc.emitStruct(ch, snmpStats.Icmp)\n\tc.emitStruct(ch, snmpStats.IcmpMsg)\n\tc.emitStruct(ch, snmpStats.Tcp)\n\tc.emitStruct(ch, snmpStats.Udp)\n\tc.emitStruct(ch, snmpStats.UdpLite)","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/prometheus/node_exporter/blob/17ddd77c59ba27e1508e9f7894b1e55b44d6aed3/collector/netstat_linux.go#L64-L100","documentation":"The netstat collector's Update reads /proc/net/netstat via the procfs library (proc.Netstat()). If the procfs parser fails to read or parse that file, Update returns this wrapped error, which the scrape framework reports as a failed collection of the netstat collector.","triggerScenarios":"c.proc.Netstat() errors when /proc/net/netstat is missing, unreadable, or has an unexpected format the procfs parser rejects (e.g. malformed kernel output or truncated file).","commonSituations":"Containers with a stripped /proc; kernel versions whose /proc/net/netstat layout isn't understood by the pinned procfs library; permission issues (hidepid).","solutions":["Verify /proc/net/netstat exists and is readable from inside the exporter's namespace (cat /proc/net/netstat).","Update the prometheus/procfs dependency (and node_exporter) to a version supporting your kernel's netstat format.","Check proc mount permissions/hidepid settings for the exporter user.","Restart the exporter / check for transient procfs read failures; if persistent, run with the same kernel the exporter was built for."],"exampleFix":"// before\nnetStats, err := c.proc.Netstat()\nif err != nil {\n\treturn fmt.Errorf(\"couldn't get netstats: %w\", err)\n}\n// after (log and continue with degraded output instead of failing the whole scrape)\nnetStats, err := c.proc.Netstat()\nif err != nil {\n\tc.logger.Warn(\"failed to read netstat; skipping netstat metrics\", \"err\", err)\n\treturn nil // or handle snmp separately\n}","handlingStrategy":"try-catch","validationCode":"import \"os\"\n// Pre-check the source file readability before scraping:\nif f, err := os.Open(*procPath + \"/self/net/netstat\"); err != nil {\n\t// skip netstat collection this scrape\n} else {\n\tf.Close()\n}","typeGuard":"null","tryCatchPattern":"// Scrape handler: log collector failure, keep serving other collectors\nif err := c.Update(ch); err != nil {\n\tif errors.Is(err, os.ErrNotExist) || errors.Is(err, os.ErrPermission) {\n\t\tlogger.Warn(\"netstat unavailable in this environment\", \"err\", err)\n\t} else {\n\t\tlogger.Error(\"netstat collection failed\", \"err\", err)\n\t}\n}","preventionTips":["Keep prometheus/procfs and node_exporter updated for kernel format changes.","Test exporter deployments inside the actual container image/kernel, not only on bare metal.","Check /proc/net/netstat availability in CI smoke tests.","Watch node_scrape_collector_success{collector=\"netstat\"} for regressions."],"tags":["linux","procfs","netstat","scrape"],"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"}