{"record":{"id":"94ccbbf4799c06ee","repo":"prometheus/node_exporter","slug":"failed-to-retrieve-bcache-stats-w","errorCode":null,"errorMessage":"failed to retrieve bcache stats: %w","messagePattern":"failed to retrieve bcache stats: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"collector/bcache_linux.go","lineNumber":66,"sourceCode":"\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}\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to retrieve bcache stats: %w\", err)\n\t}\n\n\tfor _, s := range stats {\n\t\tc.updateBcacheStats(ch, s)\n\t}\n\treturn nil\n}\n\ntype bcacheMetric struct {\n\tname            string\n\tdesc            string\n\tvalue           float64\n\tmetricType      prometheus.ValueType\n\textraLabel      []string\n\textraLabelValue string\n}\n\nfunc bcachePeriodStatsToMetric(ps *bcache.PeriodStats, labelValue string) []bcacheMetric {","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/prometheus/node_exporter/blob/17ddd77c59ba27e1508e9f7894b1e55b44d6aed3/collector/bcache_linux.go#L48-L84","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\n if err := c.Update(ch); err != nil {\n\tlogger.Error(err.Error())\n }\n// after\n if err := c.Update(ch); err != nil {\n\tif os.IsNotExist(errors.Unwrap(err)) {\n\t\tlogger.Warn(\"bcache device removed; skipping scrape\")\n\t} else {\n\t\tlogger.Error(err.Error())\n\t}\n }","handlingStrategy":"retry","validationCode":"if fi, err := os.Stat(\"/sys/fs/bcache\"); err != nil || len(dirEntries) == 0 { /* skip scrape */ }","typeGuard":null,"tryCatchPattern":"err := collector.Update(ch)\nif err != nil {\n\tvar pe *os.PathError\n\tif errors.As(err, &pe) && errors.Is(pe.Err, syscall.ENODEV) {\n\t\tlogger.Warn(\"bcache device detached; will retry next scrape\")\n\t}\n}","preventionTips":["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"],"tags":["linux","sysfs","scrape","bcache"],"backgroundTag":"file-read-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"}