prometheus/node_exporter · error

error obtaining power_supply class info

Error message

error obtaining power_supply class info: %w

What it means

getPowerSupplyClassInfo uses the procfs library's fs.PowerSupplyClass() to enumerate /sys/class/power_supply. When that underlying call fails, the error is wrapped as "error obtaining power_supply class info". This is the low-level failure point beneath the collector's Update; it indicates sysfs could not be read or parsed, not merely absence of power supplies.

Solutions

  1. Check that the configured sysfs path (--path.sysfs) contains a readable class/power_supply directory.
  2. Reproduce with a manual read: ls /sys/class/power_supply and cat the attribute files to find unreadable/odd entries.
  3. If a specific device's attributes fail to parse, note the kernel version and update procfs/node_exporter, or ignore the device via the collector's ignore pattern (--collector.powersupplyclass.ignored-inodes/pattern as available).

Example fix

// before
node_exporter --path.sysfs=/wrong/sys
// after
node_exporter --path.sysfs=/sys
Defensive patterns

Strategy: validation

Validate before calling

func sysfsReady(path string) error {
	p := filepath.Join(path, "class", "power_supply")
	entries, err := os.ReadDir(p)
	if err != nil {
		return fmt.Errorf("cannot list %s: %w", p, err)
	}
	for _, e := range entries {
		if _, err := os.ReadDir(filepath.Join(p, e.Name())); err != nil {
			return fmt.Errorf("cannot read device %s: %w", e.Name(), err)
		}
	}
	return nil
}

Try / catch

if err := sysfsReady(*sysPath); err != nil {
	logger.Warn("sysfs power_supply unreadable; skipping collector", "err", err)
} else {
	registry.MustRegister(collector)
}

Prevention

When it happens

Trigger: Called from Update: fs.PowerSupplyClass() returns an error — the procfs filesystem handle points at a path where /sys/class/power_supply cannot be listed or its attribute files read/parsed.

Common situations: --path.sysfs pointing at a wrong/unmounted directory; containers with an incomplete /sys; sysfs attribute files containing values procfs cannot parse on unusual kernels or exotic power supply devices.

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

Appendix: source

Thrown at collector/powersupplyclass_linux.go:165

	fieldDesc := prometheus.NewDesc(
		prometheus.BuildFQName(namespace, subsystem, name),
		fmt.Sprintf("%s value of /sys/class/power_supply/<power_supply>.", name),
		[]string{"power_supply"},
		nil,
	)

	ch <- prometheus.MustNewConstMetric(fieldDesc, valueType, value, powerSupplyName)
}

func getPowerSupplyClassInfo(ignore *regexp.Regexp) (sysfs.PowerSupplyClass, error) {
	fs, err := sysfs.NewFS(*sysPath)
	if err != nil {
		return nil, err
	}
	powerSupplyClass, err := fs.PowerSupplyClass()

	if err != nil {
		return powerSupplyClass, fmt.Errorf("error obtaining power_supply class info: %w", err)
	}

	for device := range powerSupplyClass {
		if ignore.MatchString(device) {
			delete(powerSupplyClass, device)
		}
	}

	return powerSupplyClass, nil
}

View on GitHub (pinned to 17ddd77c59)