prometheus/node_exporter · error

couldn't get diskstats

Error message

couldn't get diskstats: %w

What it means

The Darwin diskstats collector's Update reads per-drive statistics via iostat.ReadDriveStats(). If the IOKit/iostat call fails, Update returns "couldn't get diskstats: %w" and the scrape for this collector errors out for that cycle.

Solutions

  1. Check the wrapped cause (%w) from iostat.ReadDriveStats to identify whether it is permission, enumeration, or parsing related.
  2. Run node_exporter outside sandboxed/restricted contexts (not inside a container without IOKit access) on macOS.
  3. Verify disks are visible to the OS: diskutil list / iostat -d shows expected drives.
  4. Update node_exporter to a version with current iostat dependency fixes if the cause is a library failure.
  5. Disable the diskstats collector on hosts where it cannot function (--no-collector.diskstats).
Defensive patterns

Strategy: try-catch

Validate before calling

// macOS: probe iostat availability before enabling the collector
out, err := exec.LookPath("iostat")
if err != nil || len(out) == 0 {
    // iostat unavailable; diskstats collector will error
}

Try / catch

if err := coll.Update(ch); err != nil {
    if strings.Contains(err.Error(), "couldn't get diskstats") {
        log.Printf("diskstats scrape skipped (iostat/IOKit): %v", err)
        return nil // or disable the collector
    }
    return err
}

Prevention

When it happens

Trigger: Update() on macOS when iostat.ReadDriveStats() errors: IOKit service access failures, no disk devices present (e.g. certain VMs), or the iostat library failing to enumerate/parse drive stats.

Common situations: Running node_exporter in a macOS VM or container lacking IOKit disk access; permission/entitlement issues preventing IOKit queries; transient hardware enumeration changes; sandboxed CI runners where iostat cannot read drive stats.

Understand the failure class

Background: "API request failed": what wrapped HTTP errors from external APIs mean and how to find the real cause — this error's family across 29 libraries.

Related errors


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

Appendix: source

Thrown at collector/diskstats_darwin.go:203

						nil,
					),
					valueType: prometheus.CounterValue,
				},
				value: func(stat *iostat.DriveStats) float64 {
					return float64(stat.WriteRetries)
				},
			},
		},

		deviceFilter: deviceFilter,
		logger:       logger,
	}, nil
}

func (c *diskstatsCollector) Update(ch chan<- prometheus.Metric) error {
	diskStats, err := iostat.ReadDriveStats()
	if err != nil {
		return fmt.Errorf("couldn't get diskstats: %w", err)
	}

	for _, stats := range diskStats {
		if c.deviceFilter.ignored(stats.Name) {
			continue
		}
		for _, desc := range c.descs {
			v := desc.value(stats)
			ch <- desc.mustNewConstMetric(v, stats.Name)
		}
	}
	return nil
}

View on GitHub (pinned to 17ddd77c59)