prometheus/node_exporter · error

failed to open sysfs

Error message

failed to open sysfs: %w

What it means

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.

Solutions

  1. Verify /sys is mounted as sysfs on the host (mount | grep sysfs) and that the process can read it
  2. Check that the --path.sysfs flag points to a directory containing the expected bcache layout if using a custom path
  3. Run the exporter in the host mount/PID namespace or mount /sys read-only into the container
  4. Disable the bcache collector (--no-collector.bcache) if the host has no bcache devices

Example fix

// before
 collector, err := collector.NewNodeCollector(logger, "bcache") // fails if /sys unreadable
// after
 if _, err := os.Stat(*sysPath); err != nil {
	logger.Warn("sysfs unavailable; skipping bcache collector")
	filters = remove(filters, "bcache")
 }
 collector, err := collector.NewNodeCollector(logger, filters...)
Defensive patterns

Strategy: fallback

Validate before calling

if _, err := os.Stat(*sysPath); err != nil { /* skip bcache collector */ }

Type guard

func sysfsAvailable(path string) bool { fi, err := os.Stat(path); return err == nil && fi.IsDir() }

Try / catch

c, err := collector.NewNodeCollector(logger)
if err != nil {
	logger.Warn("bcache collector unavailable", "err", err)
	c = nil // run without bcache metrics
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "open() failed", "failed to open file", "cannot create file" — what a file open error means and how to fix it — this error's family across 42 libraries.

Related errors


AI-assisted analysis of prometheus/node_exporter@17ddd77c59 (2026-09-07). Data as JSON: /api/errors/65f73f72b3cd5fc6. Report an issue: GitHub.

Appendix: source

Thrown at collector/bcache_linux.go:46

	priorityStats = kingpin.Flag("collector.bcache.priorityStats", "Expose expensive priority stats.").Bool()
)

func init() {
	registerCollector("bcache", defaultEnabled, NewBcacheCollector)
}

// A bcacheCollector is a Collector which gathers metrics from Linux bcache.
type bcacheCollector struct {
	fs     bcache.FS
	logger *slog.Logger
}

// NewBcacheCollector returns a newly allocated bcacheCollector.
// It exposes a number of Linux bcache statistics.
func NewBcacheCollector(logger *slog.Logger) (Collector, error) {
	fs, err := bcache.NewFS(*sysPath)
	if err != nil {
		return nil, fmt.Errorf("failed to open sysfs: %w", err)
	}

	return &bcacheCollector{
		fs:     fs,
		logger: logger,
	}, nil
}

// Update reads and exposes bcache stats.
// It implements the Collector interface.
func (c *bcacheCollector) Update(ch chan<- prometheus.Metric) error {
	var stats []*bcache.Stats
	var err error
	if *priorityStats {
		stats, err = c.fs.Stats()
	} else {
		stats, err = c.fs.StatsWithoutPriority()
	}

View on GitHub (pinned to 17ddd77c59)