{"record":{"id":"69cd889a9698b352","repo":"prometheus/node_exporter","slug":"failed-to-open-sysfs-w-69cd88","errorCode":null,"errorMessage":"failed to open sysfs: %w","messagePattern":"failed to open sysfs: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"collector/diskstats_linux.go","lineNumber":92,"sourceCode":"\tdescs                   []typedDesc\n\tfilesystemInfoDesc      typedDesc\n\tdeviceMapperInfoDesc    typedDesc\n\tataDescs                map[string]typedDesc\n\tlogger                  *slog.Logger\n\tgetUdevDeviceProperties func(uint32, uint32) (udevInfo, error)\n}\n\nfunc init() {\n\tregisterCollector(\"diskstats\", defaultEnabled, NewDiskstatsCollector)\n}\n\n// NewDiskstatsCollector returns a new Collector exposing disk device stats.\n// Docs from https://www.kernel.org/doc/Documentation/iostats.txt\nfunc NewDiskstatsCollector(logger *slog.Logger) (Collector, error) {\n\tvar diskLabelNames = []string{\"device\"}\n\tfs, err := blockdevice.NewFS(*procPath, *sysPath)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to open sysfs: %w\", err)\n\t}\n\n\tdeviceFilter, err := newDiskstatsDeviceFilter(logger)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to parse device filter flags: %w\", err)\n\t}\n\n\tcollector := diskstatsCollector{\n\t\tdeviceFilter: deviceFilter,\n\t\tfs:           fs,\n\t\tinfoDesc: typedDesc{\n\t\t\tdesc: prometheus.NewDesc(prometheus.BuildFQName(namespace, diskSubsystem, \"info\"),\n\t\t\t\t\"Info of /sys/block/<block_device>.\",\n\t\t\t\t[]string{\"device\", \"major\", \"minor\", \"path\", \"wwn\", \"model\", \"serial\", \"revision\", \"rotational\"},\n\t\t\t\tnil,\n\t\t\t), valueType: prometheus.GaugeValue,\n\t\t},\n\t\tdescs: []typedDesc{","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/prometheus/node_exporter/blob/17ddd77c59ba27e1508e9f7894b1e55b44d6aed3/collector/diskstats_linux.go#L74-L110","documentation":"On Linux, NewDiskstatsCollector opens the proc/sys filesystem with blockdevice.NewFS(*procPath, *sysPath) before building the collector. If that filesystem handle cannot be created (path missing, not a directory, or stat/permission errors), construction fails with \"failed to open sysfs: %w\".","triggerScenarios":"node_exporter startup with the diskstats collector enabled when blockdevice.NewFS fails: --path.procfs or --path.sysfs points to a nonexistent/non-directory path, or permission errors occur validating either mount.","commonSituations":"Wrong --path.procfs/--path.sysfs values; containers missing /proc or /sys mounts; restricted environments where the exporter user cannot stat those paths; chroot/minimal images without the expected mounts.","solutions":["Verify both paths exist and are directories: ls -d /proc /sys (or the values of --path.procfs / --path.sysfs).","In containers, mount /proc and /sys into the container (e.g. -v /proc:/host/proc:ro -v /sys:/host/sys:ro with matching --path.* flags).","Fix the incorrect --path.procfs / --path.sysfs flag values.","Inspect the wrapped cause (%w) for permission errors and adjust the run user or mount options.","Disable the diskstats collector if disk metrics are not required (--no-collector.diskstats)."],"exampleFix":"// before (container without mounts)\ndocker run prom/node-exporter --path.procfs=/host/proc\n// after\n docker run -v /proc:/host/proc:ro -v /sys:/host/sys:ro prom/node-exporter --path.procfs=/host/proc --path.sysfs=/host/sys","handlingStrategy":"validation","validationCode":"for _, p := range []string{procPath, sysPath} {\n    fi, err := os.Stat(p)\n    if err != nil || !fi.IsDir() {\n        // invalid --path.procfs/--path.sysfs; fix before starting\n    }\n}","typeGuard":null,"tryCatchPattern":"if _, err := NewDiskstatsCollector(logger); err != nil {\n    var perr *fs.PathError\n    if errors.As(err, &perr) {\n        log.Fatalf(\"proc/sys path invalid: %v\", perr)\n    }\n    log.Fatalf(\"diskstats init failed: %v\", err)\n}","preventionTips":["Mount both /proc and /sys read-only into containers with matching --path.* flags.","Verify path flags in deployment tooling before rollout.","Run the exporter as a user that can stat proc/sys mounts.","Disable the diskstats collector on hosts without these mounts."],"tags":["linux","procfs","sysfs","diskstats"],"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"}