{"record":{"id":"bca115b42cf0836b","repo":"prometheus/node_exporter","slug":"failed-to-open-sysfs-w-bca115","errorCode":null,"errorMessage":"failed to open sysfs: %w","messagePattern":"failed to open sysfs: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"collector/bcachefs_linux.go","lineNumber":124,"sourceCode":"\t\tnil,\n\t)\n)\n\nfunc init() {\n\tregisterCollector(subsystem, defaultEnabled, NewBcachefsCollector)\n}\n\n// bcachefsCollector collects metrics from bcachefs filesystems.\ntype bcachefsCollector struct {\n\tfs     bcachefs.FS\n\tlogger *slog.Logger\n}\n\n// NewBcachefsCollector returns a new Collector exposing bcachefs statistics.\nfunc NewBcachefsCollector(logger *slog.Logger) (Collector, error) {\n\tfs, err := bcachefs.NewFS(*sysPath)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to open sysfs: %w\", err)\n\t}\n\n\treturn &bcachefsCollector{\n\t\tfs:     fs,\n\t\tlogger: logger,\n\t}, nil\n}\n\n// Update retrieves and exports bcachefs statistics.\nfunc (c *bcachefsCollector) Update(ch chan<- prometheus.Metric) error {\n\tstats, err := c.fs.Stats()\n\tif err != nil {\n\t\tif os.IsNotExist(err) {\n\t\t\tc.logger.Debug(\"bcachefs sysfs path does not exist\", \"path\", sysFilePath(\"fs/bcachefs\"))\n\t\t\treturn ErrNoData\n\t\t}\n\t\treturn fmt.Errorf(\"failed to retrieve bcachefs stats: %w\", err)\n\t}","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/prometheus/node_exporter/blob/17ddd77c59ba27e1508e9f7894b1e55b44d6aed3/collector/bcachefs_linux.go#L106-L142","documentation":"NewBcachefsCollector wraps errors from bcachefs.NewFS(*sysPath) in \"failed to open sysfs\". The constructor could not establish a filesystem handle over the sysfs root needed to read /sys/fs/bcachefs statistics, so the collector is not created. Occurs before any metric collection begins.","triggerScenarios":"Enabling the bcachefs collector on a system where /sys is not mounted as sysfs, the path given via --path.sysfs is invalid, or the underlying NewFS call fails due to permission or path errors.","commonSituations":"Running node_exporter in minimal containers without sysfs, non-Linux hosts where the build-tag-gated collector is still exercised in tests, misconfigured --path.sysfs in chrooted/unit-test setups, or very old kernels lacking bcachefs support directories.","solutions":["Confirm /sys is a mounted sysfs and readable by the exporter process","Fix the --path.sysfs flag if it was pointed at a non-existent or wrong directory","Disable the bcachefs collector (--no-collector.bcachefs) on hosts without bcachefs filesystems","Check LSM (SELinux/AppArmor) logs for denials on /sys access"],"exampleFix":"// before\n c, err := NewNodeCollector(logger, \"bcachefs\")\n// after\n if _, err := os.Stat(filepath.Join(*sysPath, \"fs\", \"bcachefs\")); err != nil {\n\tlogger.Info(\"bcachefs sysfs not present; skipping collector\")\n } else {\n\tc, err = NewNodeCollector(logger, \"bcachefs\")\n }","handlingStrategy":"fallback","validationCode":"if _, err := os.Stat(filepath.Join(*sysPath, \"fs\", \"bcachefs\")); err != nil { /* skip bcachefs collector */ }","typeGuard":"func bcachefsSysfsPresent(sysPath string) bool { _, err := os.Stat(filepath.Join(sysPath, \"fs\", \"bcachefs\")); return err == nil }","tryCatchPattern":"c, err := collector.NewNodeCollector(logger)\nif err != nil {\n\tlogger.Warn(\"bcachefs collector unavailable\", \"err\", err)\n\tc = nil\n}","preventionTips":["Only enable bcachefs collector on kernels with bcachefs mounted","Verify sysfs mount before starting exporter","Use host namespaces in containerized deployments","Test --path.sysfs overrides in staging first"],"tags":["linux","sysfs","collector-init","bcachefs"],"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"}