prometheus/node_exporter · error

failed to parse device filter flags

Error message

failed to parse device filter flags: %w

What it means

On Darwin, NewDiskstatsCollector calls newDiskstatsDeviceFilter(logger) to compile the device include/exclude regex flags. An invalid regular expression in those flags makes construction fail with "failed to parse device filter flags: %w", so the diskstats collector is not created.

Solutions

  1. Read the wrapped regexp error (%w) to locate the syntax mistake and correct the flag value.
  2. Single-quote the flag on the command line so the shell does not alter characters like [ and ].
  3. Validate the regex with a Go regexp tester before deploying.
  4. Drop the filter flag to confirm the collector works without it, then reintroduce a fixed pattern.

Example fix

// before
--collector.diskstats.device-exclude=disk[s
// after
--collector.diskstats.device-exclude='disk\d+'
Defensive patterns

Strategy: validation

Validate before calling

if _, err := regexp.Compile(deviceExclude); err != nil {
    // reject invalid --collector.diskstats.device-exclude before start
}

Try / catch

if err := runExporter(); err != nil {
    if strings.Contains(err.Error(), "failed to parse device filter flags") {
        log.Fatalf("invalid diskstats device filter regex: %v", err)
    }
    log.Fatal(err)
}

Prevention

When it happens

Trigger: node_exporter startup on macOS with --collector.diskstats.device-exclude (or include) set to a value that fails regexp.Compile; or a direct NewDiskstatsCollector call with the same bad flag value.

Common situations: Unquoted flag values mangled by the shell (e.g. disk[0-1] expanded as a glob), hand-written patterns with unbalanced brackets/parens, or patterns copied from Linux tooling using unsupported syntax.

Understand the failure class

Related errors


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

Appendix: source

Thrown at collector/diskstats_darwin.go:50

type diskstatsCollector struct {
	descs []typedDescFunc

	deviceFilter deviceFilter
	logger       *slog.Logger
}

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

// NewDiskstatsCollector returns a new Collector exposing disk device stats.
func NewDiskstatsCollector(logger *slog.Logger) (Collector, error) {
	var diskLabelNames = []string{"device"}

	deviceFilter, err := newDiskstatsDeviceFilter(logger)
	if err != nil {
		return nil, fmt.Errorf("failed to parse device filter flags: %w", err)
	}

	return &diskstatsCollector{
		descs: []typedDescFunc{
			{
				typedDesc: typedDesc{
					desc:      readsCompletedDesc,
					valueType: prometheus.CounterValue,
				},
				value: func(stat *iostat.DriveStats) float64 {
					return float64(stat.NumRead)
				},
			},
			{
				typedDesc: typedDesc{
					desc: prometheus.NewDesc(
						prometheus.BuildFQName(namespace, diskSubsystem, "read_sectors_total"),
						"The total number of sectors read successfully.",

View on GitHub (pinned to 17ddd77c59)