prometheus/node_exporter · error

sysctl has only one value, but expected

Error message

sysctl %s has only one value, but expected %v

What it means

A scalar sysctl (exactly one value) was configured as if it were a multi-value/mapped sysctl: keys were supplied via the flags, but the value has no components to map them onto. newMetrics rejects this combination.

Solutions

  1. Remove the ':key1,key2' suffix so the sysctl is exported as a single scalar metric
  2. Or target a genuinely multi-value sysctl that matches the number of keys
  3. Check `cat /proc/sys/<name>`: one token means no keys allowed

Example fix

// before
--collector.sysctl.include='net.ipv4.ip_forward:enabled,disabled'
// after
--collector.sysctl.include='net.ipv4.ip_forward'
Defensive patterns

Strategy: validation

Validate before calling

n := len(strings.Fields(string(data))) // data from /proc/sys/<name>
if n != 1 && len(keys) > 0 { return errors.New("scalar sysctl cannot have keys") }

Try / catch

if err != nil && strings.Contains(err.Error(), "has only one value") { /* fix flag config and restart */ }

Prevention

When it happens

Trigger: Running node_exporter with --collector.sysctl.include='name:key1,key2' (or with key definitions) against a sysctl that returns a single value.

Common situations: Copy-pasting a multi-key config entry for a scalar tunable like net.ipv4.ip_forward; confusing comma-separated key syntax with value lists.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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

Appendix: source

Thrown at collector/sysctl_linux.go:113

		values, err = c.fs.SysctlInts(s.name)
		if err != nil {
			return nil, fmt.Errorf("error obtaining sysctl info: %w", err)
		}
		length = len(values.([]int))
	} else {
		values, err = c.fs.SysctlStrings(s.name)
		if err != nil {
			return nil, fmt.Errorf("error obtaining sysctl info: %w", err)
		}
		length = len(values.([]string))
	}

	switch length {
	case 0:
		return nil, fmt.Errorf("sysctl %s has no values", s.name)
	case 1:
		if len(s.keys) > 0 {
			return nil, fmt.Errorf("sysctl %s has only one value, but expected %v", s.name, s.keys)
		}
		return []prometheus.Metric{s.newConstMetric(values)}, nil

	default:

		if len(s.keys) == 0 {
			return s.newIndexedMetrics(values), nil
		}

		if length != len(s.keys) {
			return nil, fmt.Errorf("sysctl %s has %d keys but only %d defined in f lag", s.name, length, len(s.keys))
		}

		return s.newMappedMetrics(values)
	}
}

type sysctl struct {

View on GitHub (pinned to 17ddd77c59)