{"record":{"id":"27307230939175a7","repo":"prometheus/node_exporter","slug":"couldn-t-get-clocksources-w","errorCode":null,"errorMessage":"couldn't get clocksources: %w","messagePattern":"couldn't get clocksources: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"collector/time_linux.go","lineNumber":34,"sourceCode":"package collector\n\nimport (\n\t\"fmt\"\n\t\"strconv\"\n\n\t\"github.com/prometheus/client_golang/prometheus\"\n\t\"github.com/prometheus/procfs/sysfs\"\n)\n\nfunc (c *timeCollector) update(ch chan<- prometheus.Metric) error {\n\tfs, err := sysfs.NewFS(*sysPath)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to open procfs: %w\", err)\n\t}\n\n\tclocksources, err := fs.ClockSources()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"couldn't get clocksources: %w\", err)\n\t}\n\tc.logger.Debug(\"in Update\", \"clocksources\", fmt.Sprintf(\"%v\", clocksources))\n\n\tfor i, clocksource := range clocksources {\n\t\tis := strconv.Itoa(i)\n\t\tfor _, cs := range clocksource.Available {\n\t\t\tch <- c.clocksourcesAvailable.mustNewConstMetric(1.0, is, cs)\n\t\t}\n\t\tch <- c.clocksourceCurrent.mustNewConstMetric(1.0, is, clocksource.Current)\n\t}\n\treturn nil\n}\n","sourceCodeStart":16,"sourceCodeEnd":47,"githubUrl":"https://github.com/prometheus/node_exporter/blob/17ddd77c59ba27e1508e9f7894b1e55b44d6aed3/collector/time_linux.go#L16-L47","documentation":"After successfully opening sysfs, the time collector calls fs.ClockSources() to enumerate /sys/devices/system/clocksource/... entries. Any read error (missing directory, unreadable files, parse failure) is wrapped as 'couldn't get clocksources: %w'. The scrape fails rather than emitting partial clocksource metrics.","triggerScenarios":"timeCollector.update when fs.ClockSources() returns an error — e.g. /sys/devices/system/clocksource absent (virtualized kernels), or individual clocksource/clockevent attributes unreadable.","commonSituations":"Minimal/VM kernels compiled without clocksource sysfs exposure, security-hardened images hiding /sys/devices, or selinux/apparmor policies denying reads of sysfs attributes.","solutions":["Check that /sys/devices/system/clocksource exists on the host.","Review MAC policy (SELinux/AppArmor) denials for sysfs reads by the exporter process.","Run the collector on the host instead of a restricted container if the kernel does not expose clocksources.","Disable the time collector on kernels lacking clocksource support."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if _, err := os.ReadDir(\"/sys/devices/system/clocksource\"); err != nil {\n    // kernel does not expose clocksources; skip time collector\n}","typeGuard":null,"tryCatchPattern":"if err := c.Update(ch); err != nil {\n    var wrapped string = err.Error()\n    if strings.Contains(wrapped, \"couldn't get clocksources\") {\n        logger.Warn(\"clocksource metrics unavailable on this kernel\", \"err\", err)\n        return\n    }\n    return err\n}","preventionTips":["Verify /sys/devices/system/clocksource exists before enabling the time collector.","Review SELinux/AppArmor audit logs for sysfs read denials.","Expect missing clocksources on some VM kernels and disable the collector there.","Keep procfs/sysfs libraries updated for kernel format changes."],"tags":["linux","sysfs","time","kernel"],"backgroundTag":"file-read-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"}