{"record":{"id":"c5b48593e41c83cd","repo":"prometheus/node_exporter","slug":"couldn-t-get-diskstats-w","errorCode":null,"errorMessage":"couldn't get diskstats: %w","messagePattern":"couldn't get diskstats: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"collector/diskstats_darwin.go","lineNumber":203,"sourceCode":"\t\t\t\t\t\tnil,\n\t\t\t\t\t),\n\t\t\t\t\tvalueType: prometheus.CounterValue,\n\t\t\t\t},\n\t\t\t\tvalue: func(stat *iostat.DriveStats) float64 {\n\t\t\t\t\treturn float64(stat.WriteRetries)\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\n\t\tdeviceFilter: deviceFilter,\n\t\tlogger:       logger,\n\t}, nil\n}\n\nfunc (c *diskstatsCollector) Update(ch chan<- prometheus.Metric) error {\n\tdiskStats, err := iostat.ReadDriveStats()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"couldn't get diskstats: %w\", err)\n\t}\n\n\tfor _, stats := range diskStats {\n\t\tif c.deviceFilter.ignored(stats.Name) {\n\t\t\tcontinue\n\t\t}\n\t\tfor _, desc := range c.descs {\n\t\t\tv := desc.value(stats)\n\t\t\tch <- desc.mustNewConstMetric(v, stats.Name)\n\t\t}\n\t}\n\treturn nil\n}\n","sourceCodeStart":185,"sourceCodeEnd":217,"githubUrl":"https://github.com/prometheus/node_exporter/blob/17ddd77c59ba27e1508e9f7894b1e55b44d6aed3/collector/diskstats_darwin.go#L185-L217","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Check the wrapped cause (%w) from iostat.ReadDriveStats to identify whether it is permission, enumeration, or parsing related.","Run node_exporter outside sandboxed/restricted contexts (not inside a container without IOKit access) on macOS.","Verify disks are visible to the OS: diskutil list / iostat -d shows expected drives.","Update node_exporter to a version with current iostat dependency fixes if the cause is a library failure.","Disable the diskstats collector on hosts where it cannot function (--no-collector.diskstats)."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// macOS: probe iostat availability before enabling the collector\nout, err := exec.LookPath(\"iostat\")\nif err != nil || len(out) == 0 {\n    // iostat unavailable; diskstats collector will error\n}","typeGuard":null,"tryCatchPattern":"if err := coll.Update(ch); err != nil {\n    if strings.Contains(err.Error(), \"couldn't get diskstats\") {\n        log.Printf(\"diskstats scrape skipped (iostat/IOKit): %v\", err)\n        return nil // or disable the collector\n    }\n    return err\n}","preventionTips":["Do not run node_exporter in macOS containers/VMs lacking IOKit disk access.","Verify iostat -d output works as the exporter user before enabling the collector.","Keep node_exporter updated for iostat library fixes.","Exclude the diskstats collector on hosts where IOKit access is restricted."],"tags":["darwin","macos","diskstats","iostat"],"backgroundTag":"api-request-failed","analyzedSha":"17ddd77c59ba27e1508e9f7894b1e55b44d6aed3","analyzedAt":"2026-09-07T17:54:06.211Z","contentChangedAt":"2026-09-07T17:54:06.211Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}