prometheus/node_exporter · error
failed to parse device filter flags
Error message
failed to parse device filter flags: %w
What it means
On Linux, after opening proc/sysfs successfully, NewDiskstatsCollector compiles the device include/exclude flag regexes via newDiskstatsDeviceFilter(logger). An invalid regular expression in those flags aborts construction with "failed to parse device filter flags: %w".
Solutions
- Use the wrapped regexp error (%w) to pinpoint the syntax problem and fix the flag value.
- Quote the pattern: --collector.diskstats.device-exclude='^(ram|loop|fd)\d+$'.
- Validate the regex against a Go regexp tester or a quick Go snippet before deploying.
- Start without the filter flag to confirm the collector initializes, then re-add a corrected pattern.
Example fix
// before --collector.diskstats.device-exclude=(ram|loop\d+$ // after --collector.diskstats.device-exclude='^(ram|loop)\d+$'
Defensive patterns
Strategy: validation
Validate before calling
if _, err := regexp.Compile(deviceExcludeFlag); err != nil {
return fmt.Errorf("invalid diskstats device filter %q: %w", deviceExcludeFlag, err)
} Try / catch
if _, err := NewDiskstatsCollector(logger); err != nil {
if strings.Contains(err.Error(), "failed to parse device filter flags") {
log.Fatalf("correct the device filter regex: %v", err)
}
log.Fatalf("diskstats init failed: %v", err)
} Prevention
- Quote regex flags in shell/JSON launch configs.
- Stick to simple anchored RE2 patterns.
- Lint launch flags in CI to catch invalid regexes before deploy.
- Test the collector locally with the same flags before host rollout.
When it happens
Trigger: node_exporter startup on Linux with --collector.diskstats.device-exclude (or include) whose value fails regexp.Compile; same for any direct call of NewDiskstatsCollector with such flags.
Common situations: Unquoted regex values altered by the shell (globs like disk* expanded, brackets eaten), unbalanced groups/brackets in hand-written patterns, or patterns copied between tools with different regex syntax.
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
- failed to open sysfs
AI-assisted analysis of prometheus/node_exporter@17ddd77c59 (2026-09-07).
Data as JSON: /api/errors/d032f9a151537ca5.
Report an issue: GitHub.
Appendix: source
Thrown at collector/diskstats_linux.go:97
getUdevDeviceProperties func(uint32, uint32) (udevInfo, error)
}
func init() {
registerCollector("diskstats", defaultEnabled, NewDiskstatsCollector)
}
// NewDiskstatsCollector returns a new Collector exposing disk device stats.
// Docs from https://www.kernel.org/doc/Documentation/iostats.txt
func NewDiskstatsCollector(logger *slog.Logger) (Collector, error) {
var diskLabelNames = []string{"device"}
fs, err := blockdevice.NewFS(*procPath, *sysPath)
if err != nil {
return nil, fmt.Errorf("failed to open sysfs: %w", err)
}
deviceFilter, err := newDiskstatsDeviceFilter(logger)
if err != nil {
return nil, fmt.Errorf("failed to parse device filter flags: %w", err)
}
collector := diskstatsCollector{
deviceFilter: deviceFilter,
fs: fs,
infoDesc: typedDesc{
desc: prometheus.NewDesc(prometheus.BuildFQName(namespace, diskSubsystem, "info"),
"Info of /sys/block/<block_device>.",
[]string{"device", "major", "minor", "path", "wwn", "model", "serial", "revision", "rotational"},
nil,
), valueType: prometheus.GaugeValue,
},
descs: []typedDesc{
{
desc: readsCompletedDesc, valueType: prometheus.CounterValue,
},
{
desc: prometheus.NewDesc(View on GitHub (pinned to 17ddd77c59)