prometheus/node_exporter · error

failed to open sysfs

Error message

failed to open sysfs: %w

What it means

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.

Solutions

  1. Confirm /sys is a mounted sysfs and readable by the exporter process
  2. Fix the --path.sysfs flag if it was pointed at a non-existent or wrong directory
  3. Disable the bcachefs collector (--no-collector.bcachefs) on hosts without bcachefs filesystems
  4. Check LSM (SELinux/AppArmor) logs for denials on /sys access

Example fix

// before
 c, err := NewNodeCollector(logger, "bcachefs")
// after
 if _, err := os.Stat(filepath.Join(*sysPath, "fs", "bcachefs")); err != nil {
	logger.Info("bcachefs sysfs not present; skipping collector")
 } else {
	c, err = NewNodeCollector(logger, "bcachefs")
 }
Defensive patterns

Strategy: fallback

Validate before calling

if _, err := os.Stat(filepath.Join(*sysPath, "fs", "bcachefs")); err != nil { /* skip bcachefs collector */ }

Type guard

func bcachefsSysfsPresent(sysPath string) bool { _, err := os.Stat(filepath.Join(sysPath, "fs", "bcachefs")); return err == nil }

Try / catch

c, err := collector.NewNodeCollector(logger)
if err != nil {
	logger.Warn("bcachefs collector unavailable", "err", err)
	c = nil
}

Prevention

When it happens

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

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

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/bca115b42cf0836b. Report an issue: GitHub.

Appendix: source

Thrown at collector/bcachefs_linux.go:124

		nil,
	)
)

func init() {
	registerCollector(subsystem, defaultEnabled, NewBcachefsCollector)
}

// bcachefsCollector collects metrics from bcachefs filesystems.
type bcachefsCollector struct {
	fs     bcachefs.FS
	logger *slog.Logger
}

// NewBcachefsCollector returns a new Collector exposing bcachefs statistics.
func NewBcachefsCollector(logger *slog.Logger) (Collector, error) {
	fs, err := bcachefs.NewFS(*sysPath)
	if err != nil {
		return nil, fmt.Errorf("failed to open sysfs: %w", err)
	}

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

// Update retrieves and exports bcachefs statistics.
func (c *bcachefsCollector) Update(ch chan<- prometheus.Metric) error {
	stats, err := c.fs.Stats()
	if err != nil {
		if os.IsNotExist(err) {
			c.logger.Debug("bcachefs sysfs path does not exist", "path", sysFilePath("fs/bcachefs"))
			return ErrNoData
		}
		return fmt.Errorf("failed to retrieve bcachefs stats: %w", err)
	}

View on GitHub (pinned to 17ddd77c59)