{"record":{"id":"66aeb237a7e9f0e7","repo":"prometheus/node_exporter","slug":"could-not-retrieve-cpu-times","errorCode":null,"errorMessage":"could not retrieve CPU times","messagePattern":"could not retrieve CPU times","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"collector/cpu_dragonfly.go","lineNumber":110,"sourceCode":"\t}, nil\n}\n\nfunc getDragonFlyCPUTimes() ([]float64, error) {\n\t// We want time spent per-CPU per CPUSTATE.\n\t// CPUSTATES (number of CPUSTATES) is defined as 5U.\n\t// States: CP_USER | CP_NICE | CP_SYS | CP_IDLE | CP_INTR\n\t//\n\t// Each value is in microseconds\n\t//\n\t// Look into sys/kern/kern_clock.c for details.\n\n\tvar (\n\t\tcpuTimesC      *C.uint64_t\n\t\tcpuTimesLength C.size_t\n\t)\n\n\tif C.getCPUTimes(&cpuTimesC, &cpuTimesLength) == -1 {\n\t\treturn nil, errors.New(\"could not retrieve CPU times\")\n\t}\n\tdefer C.free(unsafe.Pointer(cpuTimesC))\n\n\tcput := (*[maxCPUTimesLen]C.uint64_t)(unsafe.Pointer(cpuTimesC))[:cpuTimesLength:cpuTimesLength]\n\n\tcpuTimes := make([]float64, cpuTimesLength)\n\tfor i, value := range cput {\n\t\tcpuTimes[i] = float64(value) / float64(1000000)\n\t}\n\treturn cpuTimes, nil\n}\n\n// Expose CPU stats using sysctl.\nfunc (c *statCollector) Update(ch chan<- prometheus.Metric) error {\n\tvar fieldsCount = 5\n\tcpuTimes, err := getDragonFlyCPUTimes()\n\tif err != nil {\n\t\treturn err","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/prometheus/node_exporter/blob/17ddd77c59ba27e1508e9f7894b1e55b44d6aed3/collector/cpu_dragonfly.go#L92-L128","documentation":"In the DragonFly BSD CPU collector (cpu_dragonfly.go), getDragonFlyCPUTimes calls the cgo helper C.getCPUTimes; when that helper returns -1 the collector has no way to read per-CPU time counters from the kernel, so it returns errors.New(\"could not retrieve CPU times\") and CPU metrics are skipped for that scrape.","triggerScenarios":"C.getCPUTimes(&cpuTimesC, &cpuTimesLength) == -1 — the underlying sysctl (kern.cp_time via cgo) failed inside the helper, e.g. sysctl unavailable, permission issue, or memory allocation failure in the C helper on DragonFly BSD.","commonSituations":"Running node_exporter on DragonFly BSD where the kern.cp_time sysctl is restricted or the kernel lacks expected CPU statistics; resource exhaustion preventing the C helper from allocating its output buffer.","solutions":["Verify 'sysctl kern.cp_time' works on the host; if it fails, fix kernel/sysctl permissions there first","Rebuild node_exporter for your DragonFly version — the cgo helper may target an older ABI","Check host memory pressure; the helper's internal allocation can fail under memory exhaustion","Disable the cpu collector if the platform cannot provide the data"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := c.Update(ch); err != nil {\n    if strings.Contains(err.Error(), \"could not retrieve CPU times\") {\n        c.logger.Warn(\"CPU times unavailable on this host\", \"err\", err)\n        return nil // degrade gracefully\n    }\n    return err\n}","preventionTips":["Pre-flight check: run 'sysctl kern.cp_time' in provisioning to confirm the host supports it","Build node_exporter with a cgo toolchain matching your DragonFly release","Monitor host memory; C-side allocations fail under pressure","Expose collector-level failure metrics so persistent failures surface"],"tags":["cgo","sysctl","cpu","dragonfly","bsd"],"backgroundTag":"system-call-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"}