prometheus/node_exporter · error

failed to get kernel random stats

Error message

failed to get kernel random stats: %w

What it means

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.

Solutions

  1. Check the underlying files: `cat /proc/sys/kernel/random/entropy_avail` and `poolsize`.
  2. Confirm the kernel exposes proc sysctls (CONFIG_PROC_SYSCTL=y); upgrade kernel if missing.
  3. In containers, ensure /proc is mounted from the host and not filtered by security policy.
  4. Disable the entropy collector (--collector.entropy=false) if the platform cannot provide it.
Defensive patterns

Strategy: validation

Validate before calling

const fs = require('fs');
const ok = ['/proc/sys/kernel/random/entropy_avail', '/proc/sys/kernel/random/poolsize']
  .every(f => fs.existsSync(f) && !isNaN(parseInt(fs.readFileSync(f, 'utf8').trim(), 10)));
if (!ok) console.warn('kernel random stats unavailable; disable --collector.entropy');

Try / catch

try {
  await scrapeNodeExporter();
} catch (e) {
  if (String(e).includes('failed to get kernel random stats')) {
    console.warn('kernel random stats unavailable; set --collector.entropy=false');
  } else throw e;
}

Prevention

When it happens

Trigger: c.fs.KernelRandom() returns an error during entropyCollector.Update: missing /proc/sys/kernel/random files or unreadable/invalid content.

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

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


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

Appendix: source

Thrown at collector/entropy_linux.go:64

)

// NewEntropyCollector returns a new Collector exposing entropy stats.
func NewEntropyCollector(logger *slog.Logger) (Collector, error) {
	fs, err := procfs.NewFS(*procPath)
	if err != nil {
		return nil, fmt.Errorf("failed to open procfs: %w", err)
	}

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

func (c *entropyCollector) Update(ch chan<- prometheus.Metric) error {
	stats, err := c.fs.KernelRandom()
	if err != nil {
		return fmt.Errorf("failed to get kernel random stats: %w", err)
	}

	if stats.EntropyAvaliable == nil {
		return fmt.Errorf("couldn't get entropy_avail")
	}
	ch <- prometheus.MustNewConstMetric(
		entropyAvail, prometheus.GaugeValue, float64(*stats.EntropyAvaliable))

	if stats.PoolSize == nil {
		return fmt.Errorf("couldn't get entropy poolsize")
	}
	ch <- prometheus.MustNewConstMetric(
		entropyPoolSize, prometheus.GaugeValue, float64(*stats.PoolSize))

	return nil
}

View on GitHub (pinned to 17ddd77c59)