prometheus/node_exporter · error

could not get power_supply class info

Error message

could not get power_supply class info: %w

What it means

The Linux power_supply_class collector's Update calls getPowerSupplyClassInfo; if it fails with an error other than os.ErrNotExist, the scrape is aborted with "could not get power_supply class info". os.ErrNotExist is deliberately translated to ErrNoData (a benign no-data scrape) — this wrapped error is the genuine-failure path, meaning /sys/class/power_supply exists but could not be read.

Solutions

  1. Verify /sys/class/power_supply is readable by the exporter user; add read permissions or run with adequate privileges.
  2. In containers, mount the host sysfs read-only: -v /sys:/host/sys:ro and set --path.sysfs=/host/sys.
  3. If the machine genuinely has no power supplies, confirm the error is os.ErrNotExist (which yields ErrNoData, not this error) and disable --collector.powersupplyclass.

Example fix

// before
docker run node-exporter  # /sys not mounted
// after
docker run -v /sys:/host/sys:ro node-exporter --path.sysfs=/host/sys
Defensive patterns

Strategy: fallback

Validate before calling

// Pre-flight check before enabling the collector
if _, err := os.Stat("/sys/class/power_supply"); err != nil {
	if os.IsNotExist(err) {
		logger.Info("no power_supply class; disabling collector")
	}
}

Try / catch

// Map ErrNoData to a clean scrape, otherwise surface the wrapped error.
if err := coll.Update(ch); err != nil {
	if errors.Is(err, ErrNoData) {
		return nil
	}
	logger.Error("powersupplyclass scrape failed", "err", err)
	return err
}

Prevention

When it happens

Trigger: Update -> getPowerSupplyClassInfo returning a non-ErrNotExist error, e.g. procfs failing to read /sys/class/power_supply entries due to permission problems or I/O errors on the sysfs files.

Common situations: node_exporter running in a container without the host's /sys mounted (partial mount or masked paths); restricted read permissions on /sys/class/power_supply; kernel without power_supply support producing unexpected sysfs states.

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/9e786e40e3c14e76. Report an issue: GitHub.

Appendix: source

Thrown at collector/powersupplyclass_linux.go:35

import (
	"errors"
	"fmt"
	"os"
	"regexp"
	"strings"

	"github.com/prometheus/client_golang/prometheus"
	"github.com/prometheus/procfs/sysfs"
)

func (c *powerSupplyClassCollector) Update(ch chan<- prometheus.Metric) error {
	powerSupplyClass, err := getPowerSupplyClassInfo(c.ignoredPattern)
	if err != nil {
		if errors.Is(err, os.ErrNotExist) {
			return ErrNoData
		}
		return fmt.Errorf("could not get power_supply class info: %w", err)
	}
	for _, powerSupply := range powerSupplyClass {

		for name, value := range map[string]*int64{
			"authentic":             powerSupply.Authentic,
			"calibrate":             powerSupply.Calibrate,
			"capacity":              powerSupply.Capacity,
			"capacity_alert_max":    powerSupply.CapacityAlertMax,
			"capacity_alert_min":    powerSupply.CapacityAlertMin,
			"cyclecount":            powerSupply.CycleCount,
			"online":                powerSupply.Online,
			"present":               powerSupply.Present,
			"time_to_empty_seconds": powerSupply.TimeToEmptyNow,
			"time_to_full_seconds":  powerSupply.TimeToFullNow,
		} {
			if value != nil {
				pushPowerSupplyMetric(ch, c.subsystem, name, float64(*value), powerSupply.Name, prometheus.GaugeValue)
			}

View on GitHub (pinned to 17ddd77c59)