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
- Read the wrapped regexp error (%w) to locate the syntax mistake and correct the flag value.
- Single-quote the flag on the command line so the shell does not alter characters like [ and ].
- Validate the regex with a Go regexp tester before deploying.
- 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
- Quote flag values to prevent shell glob expansion of [ and ? characters.
- Use Go/RE2-compatible syntax only in filter patterns.
- Keep filter patterns in version-controlled launch configs and lint them.
- Fall back to no filter if a pattern fails validation in config tooling.
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
- 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
- couldn't get diskstats
- failed to parse device filter flags
- failed to parse device filter flags
- failed to parse device filter flags
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)