{"record":{"id":"a9fe9116c4588bc9","repo":"prometheus/node_exporter","slug":"failed-to-get-kernel-random-stats-w","errorCode":null,"errorMessage":"failed to get kernel random stats: %w","messagePattern":"failed to get kernel random stats: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"collector/entropy_linux.go","lineNumber":64,"sourceCode":")\n\n// NewEntropyCollector returns a new Collector exposing entropy stats.\nfunc NewEntropyCollector(logger *slog.Logger) (Collector, error) {\n\tfs, err := procfs.NewFS(*procPath)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to open procfs: %w\", err)\n\t}\n\n\treturn &entropyCollector{\n\t\tfs:     fs,\n\t\tlogger: logger,\n\t}, nil\n}\n\nfunc (c *entropyCollector) Update(ch chan<- prometheus.Metric) error {\n\tstats, err := c.fs.KernelRandom()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to get kernel random stats: %w\", err)\n\t}\n\n\tif stats.EntropyAvaliable == nil {\n\t\treturn fmt.Errorf(\"couldn't get entropy_avail\")\n\t}\n\tch <- prometheus.MustNewConstMetric(\n\t\tentropyAvail, prometheus.GaugeValue, float64(*stats.EntropyAvaliable))\n\n\tif stats.PoolSize == nil {\n\t\treturn fmt.Errorf(\"couldn't get entropy poolsize\")\n\t}\n\tch <- prometheus.MustNewConstMetric(\n\t\tentropyPoolSize, prometheus.GaugeValue, float64(*stats.PoolSize))\n\n\treturn nil\n}\n","sourceCodeStart":46,"sourceCodeEnd":81,"githubUrl":"https://github.com/prometheus/node_exporter/blob/17ddd77c59ba27e1508e9f7894b1e55b44d6aed3/collector/entropy_linux.go#L46-L81","documentation":"During Update, the entropy collector calls fs.KernelRandom(), which parses /proc/sys/kernel/random (entropy_avail, poolsize). If that read/parse fails, Update returns 'failed to get kernel random stats' with the wrapped cause, and the scrape for this collector fails. This indicates the kernel is not exposing the random subsystem files procfs expects.","triggerScenarios":"c.fs.KernelRandom() returns an error during entropyCollector.Update: missing /proc/sys/kernel/random files or unreadable/invalid content.","commonSituations":"Very old or hardened kernels lacking the random sysctl files; /proc partially masked in containers (e.g. lxcfs or seccomp filtering); kernel config without CONFIG_PROC_SYSCTL; random module state changing mid-read.","solutions":["Check the underlying files: `cat /proc/sys/kernel/random/entropy_avail` and `poolsize`.","Confirm the kernel exposes proc sysctls (CONFIG_PROC_SYSCTL=y); upgrade kernel if missing.","In containers, ensure /proc is mounted from the host and not filtered by security policy.","Disable the entropy collector (--collector.entropy=false) if the platform cannot provide it."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const fs = require('fs');\nconst ok = ['/proc/sys/kernel/random/entropy_avail', '/proc/sys/kernel/random/poolsize']\n  .every(f => fs.existsSync(f) && !isNaN(parseInt(fs.readFileSync(f, 'utf8').trim(), 10)));\nif (!ok) console.warn('kernel random stats unavailable; disable --collector.entropy');","typeGuard":null,"tryCatchPattern":"try {\n  await scrapeNodeExporter();\n} catch (e) {\n  if (String(e).includes('failed to get kernel random stats')) {\n    console.warn('kernel random stats unavailable; set --collector.entropy=false');\n  } else throw e;\n}","preventionTips":["Verify /proc/sys/kernel/random files exist before enabling the entropy collector.","Use kernels with CONFIG_PROC_SYSCTL enabled.","Avoid filtered /proc implementations (lxcfs) or account for them in collector flags."],"tags":["linux","procfs","entropy","kernel"],"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"}