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
- Check the wrapped error (%w) for the exact regexp compile position and fix the pattern passed to the device filter flag.
- Quote the flag value in the shell: --collector.diskstats.device-exclude='^(ram|loop)\d+$'.
- Test the pattern standalone (e.g. go run with regexp.MatchString, or an online Go regex tester) before adding it to the exporter flags.
- 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
- Single-quote regex flag values in shell scripts.
- Prefer simple anchored patterns like '^(ram|loop)\d+$'.
- Test patterns in a Go RE2 regex tester before rollout.
- Validate flags in config management (Ansible/Puppet) before shipping to hosts.
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
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- failed to parse device filter flags
- failed to parse device filter flags
- failed to parse device filter flags
- failed to parse device filter flags
- --collector.diskstats.ignored-devices and…
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)