{"record":{"id":"e3c6d46094e84760","repo":"prometheus/node_exporter","slug":"failed-to-open-procfs-w-e3c6d4","errorCode":null,"errorMessage":"failed to open procfs: %w","messagePattern":"failed to open procfs: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"collector/netstat_linux.go","lineNumber":61,"sourceCode":")\n\ntype netStatCollector struct {\n\tproc         procfs.Proc\n\tfieldPattern *regexp.Regexp\n\tlogger       *slog.Logger\n}\n\nfunc init() {\n\tregisterCollector(\"netstat\", defaultEnabled, NewNetStatCollector)\n}\n\n// NewNetStatCollector takes and returns\n// a new Collector exposing network stats.\nfunc NewNetStatCollector(logger *slog.Logger) (Collector, error) {\n\tpattern := regexp.MustCompile(*netStatFields)\n\tfs, err := procfs.NewFS(*procPath)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to open procfs: %w\", err)\n\t}\n\n\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 {","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/prometheus/node_exporter/blob/17ddd77c59ba27e1508e9f7894b1e55b44d6aed3/collector/netstat_linux.go#L43-L79","documentation":"NewNetStatCollector initializes the Linux netstat collector by opening the procfs filesystem at the path given by the --path.procfs flag via procfs.NewFS. If procfs cannot be opened/mounted at that path, the collector constructor fails with this wrapped error and the collector is not registered.","triggerScenarios":"Calling NewNetStatCollector when *procPath points to a directory that does not exist, is not readable, or is not a procfs filesystem (procfs.NewFS validates the mount).","commonSituations":"Running node_exporter in a container without /proc mounted or mounted elsewhere; passing a wrong --path.procfs value; running on a non-Linux host or a restricted environment where /proc access is blocked.","solutions":["Ensure /proc exists and is a mounted procfs filesystem (mount | grep proc).","Check the --path.procfs flag points at the correct procfs root (default /proc).","In containers, mount /proc into the container (e.g. docker run -v /proc:/host/proc:ro and --path.procfs=/host/proc).","Verify filesystem permissions allow the node_exporter user to read the procfs path."],"exampleFix":"// before\nfs, err := procfs.NewFS(*procPath)\nif err != nil {\n\treturn nil, fmt.Errorf(\"failed to open procfs: %w\", err)\n}\n// after (fail fast with an actionable hint)\nfs, err := procfs.NewFS(*procPath)\nif err != nil {\n\treturn nil, fmt.Errorf(\"failed to open procfs at %q (is it mounted? is --path.procfs correct?): %w\", *procPath, err)\n}","handlingStrategy":"validation","validationCode":"import \"os\"\n// Call before starting the collector:\nif st, err := os.Stat(*procPath); err != nil || !st.IsDir() {\n\t// fail fast: procfs path missing or not a directory\n}","typeGuard":"null","tryCatchPattern":"// Wrap collector construction and fail startup with context\nif _, err := NewNetStatCollector(logger); err != nil {\n\tlogger.Error(\"netstat collector init failed\", \"err\", err)\n\tos.Exit(1)\n}","preventionTips":["Always mount /proc (read-only is fine) in containers running the exporter.","Verify --path.procfs explicitly in deployment configs/Helm values.","Smoke-test `cat $PROC_PATH/net/netstat` in entrypoint scripts before starting the exporter.","Keep the exporter user's permissions sufficient to traverse /proc."],"tags":["linux","procfs","netstat","filesystem"],"backgroundTag":"file-open-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"}