{"record":{"id":"65f73f72b3cd5fc6","repo":"prometheus/node_exporter","slug":"failed-to-open-sysfs-w","errorCode":null,"errorMessage":"failed to open sysfs: %w","messagePattern":"failed to open sysfs: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"collector/bcache_linux.go","lineNumber":46,"sourceCode":"\tpriorityStats = kingpin.Flag(\"collector.bcache.priorityStats\", \"Expose expensive priority stats.\").Bool()\n)\n\nfunc init() {\n\tregisterCollector(\"bcache\", defaultEnabled, NewBcacheCollector)\n}\n\n// A bcacheCollector is a Collector which gathers metrics from Linux bcache.\ntype bcacheCollector struct {\n\tfs     bcache.FS\n\tlogger *slog.Logger\n}\n\n// NewBcacheCollector returns a newly allocated bcacheCollector.\n// It exposes a number of Linux bcache statistics.\nfunc NewBcacheCollector(logger *slog.Logger) (Collector, error) {\n\tfs, err := bcache.NewFS(*sysPath)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to open sysfs: %w\", err)\n\t}\n\n\treturn &bcacheCollector{\n\t\tfs:     fs,\n\t\tlogger: logger,\n\t}, nil\n}\n\n// Update reads and exposes bcache stats.\n// It implements the Collector interface.\nfunc (c *bcacheCollector) Update(ch chan<- prometheus.Metric) error {\n\tvar stats []*bcache.Stats\n\tvar err error\n\tif *priorityStats {\n\t\tstats, err = c.fs.Stats()\n\t} else {\n\t\tstats, err = c.fs.StatsWithoutPriority()\n\t}","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/prometheus/node_exporter/blob/17ddd77c59ba27e1508e9f7894b1e55b44d6aed3/collector/bcache_linux.go#L28-L64","documentation":"NewBcacheCollector wraps any error returned by bcache.NewFS(*sysPath) (default /sys) in \"failed to open sysfs\". The procfs-based bcache package returns errors when the sysfs mount point cannot be accessed or is not a valid filesystem handle, so the collector cannot be constructed. This makes the bcache collector unavailable at startup.","triggerScenarios":"Calling NewNodeCollector with the bcache collector enabled on a system where /sys is missing, not mounted (sysfs), unreadable due to permissions/namespacing, or when running on non-Linux platforms where bcache.NewFS fails on the given path.","commonSituations":"Running node_exporter inside a container with a masked or absent /sys/sys/fs/bcache hierarchy, restricted containers (no sysfs mount), SELinux/AppArmor denials, or enabling --collector.bcache on hosts (or chroots) without a real sysfs.","solutions":["Verify /sys is mounted as sysfs on the host (mount | grep sysfs) and that the process can read it","Check that the --path.sysfs flag points to a directory containing the expected bcache layout if using a custom path","Run the exporter in the host mount/PID namespace or mount /sys read-only into the container","Disable the bcache collector (--no-collector.bcache) if the host has no bcache devices"],"exampleFix":"// before\n collector, err := collector.NewNodeCollector(logger, \"bcache\") // fails if /sys unreadable\n// after\n if _, err := os.Stat(*sysPath); err != nil {\n\tlogger.Warn(\"sysfs unavailable; skipping bcache collector\")\n\tfilters = remove(filters, \"bcache\")\n }\n collector, err := collector.NewNodeCollector(logger, filters...)","handlingStrategy":"fallback","validationCode":"if _, err := os.Stat(*sysPath); err != nil { /* skip bcache collector */ }","typeGuard":"func sysfsAvailable(path string) bool { fi, err := os.Stat(path); return err == nil && fi.IsDir() }","tryCatchPattern":"c, err := collector.NewNodeCollector(logger)\nif err != nil {\n\tlogger.Warn(\"bcache collector unavailable\", \"err\", err)\n\tc = nil // run without bcache metrics\n}","preventionTips":["Mount /sys read-only into containers running node_exporter","Validate --path.sysfs points at a real sysfs mount before startup","Keep exporter in host mount namespace for full sysfs visibility","Disable bcache collector on hosts without bcache devices"],"tags":["linux","sysfs","collector-init","bcache"],"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"}