prometheus/node_exporter · error

failed to parse device filter flags

Error message

failed to parse device filter flags: %w

What it means

On AIX, NewDiskstatsCollector builds a device filter from the --collector.diskstats.device-exclude / device-include style flags via newDiskstatsDeviceFilter(logger). When compiling those regular expressions fails, construction is aborted with "failed to parse device filter flags: %w".

Solutions

  1. Check the wrapped error (%w) for the exact regexp compile position and fix the pattern passed to the device filter flag.
  2. Quote the flag value in the shell: --collector.diskstats.device-exclude='^(ram|loop)\d+$'.
  3. Test the pattern standalone (e.g. go run with regexp.MatchString, or an online Go regex tester) before adding it to the exporter flags.
  4. Remove the filter flag entirely to collect all devices, then re-add a corrected pattern.

Example fix

// before
--collector.diskstats.device-exclude=^(ram|loop)+$
// after (balanced group, quoted)
--collector.diskstats.device-exclude='^(ram|loop)\d+$'
Defensive patterns

Strategy: validation

Validate before calling

if _, err := regexp.Compile(deviceFilterFlag); err != nil {
    return fmt.Errorf("invalid device filter %q: %w", deviceFilterFlag, err)
}

Try / catch

if _, err := NewDiskstatsCollector(logger); err != nil {
    if strings.Contains(err.Error(), "failed to parse device filter flags") {
        log.Fatalf("fix --collector.diskstats.device-* regex: %v", err)
    }
    log.Fatalf("diskstats init failed: %v", err)
}

Prevention

When it happens

Trigger: node_exporter startup (or direct NewDiskstatsCollector call) with a device filter flag whose value is not a valid regular expression, causing regexp.Compile to fail inside newDiskstatsDeviceFilter.

Common situations: Users passing shell-reserved characters into the flag without quoting (e.g. unescaped parens or a bare |), typos in regex syntax like 'sd[a-z](' or 'sd.*[', or copy-pasted filter patterns from other tools with different regex dialects.

Understand the failure class

Related errors


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

Appendix: source

Thrown at collector/diskstats_aix.go:59

	deviceFilter deviceFilter
	logger       *slog.Logger

	tickPerSecond float64
}

func init() {
	registerCollector("diskstats", defaultEnabled, NewDiskstatsCollector)
}

// NewDiskstatsCollector returns a new Collector exposing disk device stats.
func NewDiskstatsCollector(logger *slog.Logger) (Collector, error) {
	ticks, err := tickPerSecond()
	if err != nil {
		return nil, err
	}
	deviceFilter, err := newDiskstatsDeviceFilter(logger)
	if err != nil {
		return nil, fmt.Errorf("failed to parse device filter flags: %w", err)
	}

	return &diskstatsCollector{
		rbytes: typedDesc{readBytesDesc, prometheus.CounterValue},
		wbytes: typedDesc{writtenBytesDesc, prometheus.CounterValue},
		time:   typedDesc{ioTimeSecondsDesc, prometheus.CounterValue},

		bsize: typedDesc{
			prometheus.NewDesc(
				prometheus.BuildFQName(namespace, diskSubsystem, "block_size_bytes"),
				"Size of the block device in bytes.",
				diskLabelNames, nil,
			),
			prometheus.GaugeValue,
		},
		qdepth: typedDesc{
			prometheus.NewDesc(
				prometheus.BuildFQName(namespace, diskSubsystem, "queue_depth"),

View on GitHub (pinned to 17ddd77c59)