prometheus/node_exporter · error
failed to retrieve bcache stats
Error message
failed to retrieve bcache stats: %w
What it means
bcacheCollector.Update calls c.fs.Stats() (or StatsWithoutPriority() when --collector.bcache.priority-stats is off) and wraps any read error in "failed to retrieve bcache stats". This means the sysfs bcache tree existed at construction but could not be read/walked during the scrape. The whole scrape for this collector fails and no bcache metrics are produced for that cycle.
Solutions
- Re-check that the bcache device still exists under /sys/fs/bcache at scrape time (ls /sys/fs/bcache)
- Check dmesg for bcache or block device errors and re-register the backing device if it was detached
- Verify file permissions/readability for the node_exporter user on the sysfs bcache files
- Update procfs dependency/kernel expectations if attributes were renamed in a newer kernel
Example fix
// before
if err := c.Update(ch); err != nil {
logger.Error(err.Error())
}
// after
if err := c.Update(ch); err != nil {
if os.IsNotExist(errors.Unwrap(err)) {
logger.Warn("bcache device removed; skipping scrape")
} else {
logger.Error(err.Error())
}
} Defensive patterns
Strategy: retry
Validate before calling
if fi, err := os.Stat("/sys/fs/bcache"); err != nil || len(dirEntries) == 0 { /* skip scrape */ } Try / catch
err := collector.Update(ch)
if err != nil {
var pe *os.PathError
if errors.As(err, &pe) && errors.Is(pe.Err, syscall.ENODEV) {
logger.Warn("bcache device detached; will retry next scrape")
}
} Prevention
- Monitor dmesg for bcache detach events
- Avoid hot-removing bcache devices during scrape windows
- Pin exporter and procfs versions compatible with your kernel
- Alert on repeated 'failed to retrieve bcache stats' occurrences
When it happens
Trigger: A periodic scrape where the /sys/fs/bcache directory disappeared (device detached), a backing device was hot-removed mid-walk, an underlying sysfs file read returned EIO/EACCES, or StatsWithoutPriority was selected and its files are unreadable.
Common situations: Hot-unplugging an SSD used as bcache cache during scraping; containers where sysfs files become unreadable; kernel version differences removing expected bcache attributes; I/O errors on the sysfs backing store.
Understand the failure class
Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.
Related errors
- failed to open sysfs
- failed to retrieve bcachefs stats
- failed to retrieve Btrfs stats from procfs
- failed to scan DM-multipath devices
- couldn't get NUMA meminfo
AI-assisted analysis of prometheus/node_exporter@17ddd77c59 (2026-09-07).
Data as JSON: /api/errors/94ccbbf4799c06ee.
Report an issue: GitHub.
Appendix: source
Thrown at collector/bcache_linux.go:66
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()
}
if err != nil {
return fmt.Errorf("failed to retrieve bcache stats: %w", err)
}
for _, s := range stats {
c.updateBcacheStats(ch, s)
}
return nil
}
type bcacheMetric struct {
name string
desc string
value float64
metricType prometheus.ValueType
extraLabel []string
extraLabelValue string
}
func bcachePeriodStatsToMetric(ps *bcache.PeriodStats, labelValue string) []bcacheMetric {View on GitHub (pinned to 17ddd77c59)