{"record":{"id":"8afb575efb5387a0","repo":"prometheus/node_exporter","slug":"couldn-t-get-snmp-stats-w","errorCode":null,"errorMessage":"couldn't get SNMP stats: %w","messagePattern":"couldn't get SNMP stats: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"collector/netstat_linux.go","lineNumber":86,"sourceCode":"\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)\n\tc.emitStruct(ch, snmp6Stats.Ip6)\n\tc.emitStruct(ch, snmp6Stats.Icmp6)\n\tc.emitStruct(ch, snmp6Stats.Udp6)\n\tc.emitStruct(ch, snmp6Stats.UdpLite6)","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/prometheus/node_exporter/blob/17ddd77c59ba27e1508e9f7894b1e55b44d6aed3/collector/netstat_linux.go#L68-L104","documentation":"The netstat collector's Update reads /proc/net/snmp via the procfs library (proc.Snmp()). If reading or parsing that file fails, Update returns this wrapped error, failing the collection of SNMP (non-SNMP6) network statistics.","triggerScenarios":"c.proc.Snmp() errors when /proc/net/snmp is missing, unreadable, or contains content the procfs parser cannot parse (unexpected header/lines).","commonSituations":"Stripped /proc in containers; kernel/procfs library version skew producing unparseable output; permission restrictions on /proc/net.","solutions":["Verify /proc/net/snmp exists and is readable (cat /proc/net/snmp).","Update prometheus/procfs and node_exporter to versions compatible with your kernel.","Check hidepid/proc mount options so the exporter user can read /proc/net.","If only SNMP parsing fails while netstat works, file an upstream issue with the kernel version and file contents."],"exampleFix":"// before\nsnmpStats, err := c.proc.Snmp()\nif err != nil {\n\treturn fmt.Errorf(\"couldn't get SNMP stats: %w\", err)\n}\n// after (contextual wrap for diagnosability)\nsnmpStats, err := c.proc.Snmp()\nif err != nil {\n\treturn fmt.Errorf(\"couldn't get SNMP stats from %s/proc/net/snmp: %w\", *procPath, err)\n}","handlingStrategy":"try-catch","validationCode":"import \"os\"\n// Verify SNMP file readability before the scrape:\nif f, err := os.Open(*procPath + \"/self/net/snmp\"); err != nil {\n\t// SNMP metrics unavailable; alert or skip\n} else {\n\tf.Close()\n}","typeGuard":"null","tryCatchPattern":"// Treat parse failures distinctly from missing files\nif err := c.Update(ch); err != nil {\n\tvar perr *os.PathError\n\tif errors.As(err, &perr) {\n\t\tlogger.Warn(\"/proc/net/snmp unreadable\", \"err\", err)\n\t} else {\n\t\tlogger.Error(\"SNMP parse failure; update procfs library\", \"err\", err)\n\t}\n}","preventionTips":["Update the procfs dependency when upgrading kernels.","Confirm /proc/net/snmp content renders sanely (cat) on new host images.","Avoid hiding /proc/net from the exporter user via mount options.","Alert on node_scrape_collector_success{collector=\"netstat\"}==0."],"tags":["linux","procfs","snmp","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"}