{"record":{"id":"dbe5dbcafd8517d7","repo":"prometheus/node_exporter","slug":"invalid-cpu-number","errorCode":null,"errorMessage":"Invalid cpu number","messagePattern":"Invalid cpu number","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"collector/cpu_netbsd.go","lineNumber":187,"sourceCode":"\t\treturn nil, err\n\t}\n\tclock := *(*clockinfo)(unsafe.Pointer(&clockb[0]))\n\n\tvar cpufreq float64\n\tif clock.stathz > 0 {\n\t\tcpufreq = float64(clock.stathz)\n\t} else {\n\t\tcpufreq = float64(clock.hz)\n\t}\n\n\tncpusb, err := unix.SysctlRaw(\"hw.ncpu\")\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tncpus := int(*(*uint32)(unsafe.Pointer(&ncpusb[0])))\n\n\tif ncpus < 1 {\n\t\treturn nil, errors.New(\"Invalid cpu number\")\n\t}\n\n\tvar times []float64\n\tfor ncpu := 0; ncpu < ncpus; ncpu++ {\n\t\tcpb, err := unix.SysctlRaw(\"kern.cp_time\", ncpu)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tfor len(cpb) >= int(unsafe.Sizeof(uint64(0))) {\n\t\t\tt := *(*uint64)(unsafe.Pointer(&cpb[0]))\n\t\t\ttimes = append(times, float64(t)/cpufreq)\n\t\t\tcpb = cpb[unsafe.Sizeof(uint64(0)):]\n\t\t}\n\t}\n\n\tcpus := make([]cputime, len(times)/states)\n\tfor i := 0; i < len(times); i += states {\n\t\tcpu := &cpus[i/states]","sourceCodeStart":169,"sourceCodeEnd":205,"githubUrl":"https://github.com/prometheus/node_exporter/blob/17ddd77c59ba27e1508e9f7894b1e55b44d6aed3/collector/cpu_netbsd.go#L169-L205","documentation":"The NetBSD CPU collector (cpu_netbsd.go) reads the number of CPUs via sysctl kern.ncpu; if ncpus is less than 1 it cannot iterate per-CPU kern.cp_time counters, so getCPUTimes returns errors.New(\"Invalid cpu number\") and CPU metrics are skipped.","triggerScenarios":"getCPUTimes on NetBSD reads kern.ncpu via unix.SysctlRaw and gets a value < 1 (0 or a garbage/byte-order-garbled value), before looping 'kern.cp_time' for each cpu index.","commonSituations":"Virtualized/containerized NetBSD guests reporting ncpu=0; kernel versions where the sysctl layout differs so the raw uint32 read is misinterpreted; unusual jail/chroot sysctl restrictions.","solutions":["Check 'sysctl -n kern.ncpu' on the host returns >= 1; fix the guest/kernel config if it reports 0","Confirm node_exporter was built for your NetBSD release; older/newer kernels may change sysctl binary layout","Upgrade node_exporter to a version matching your NetBSD version's golang.org/x/sys unix wrappers","Disable the cpu collector on affected hosts as a workaround"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// shell pre-flight on the host: kern.ncpu must be >= 1\n[ \"$(sysctl -n kern.ncpu 2>/dev/null || echo 0)\" -ge 1 ] || echo \"kern.ncpu invalid; cpu collector will fail\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Verify kern.ncpu is sane on NetBSD guests/jails before deploying the exporter","Match node_exporter version to the NetBSD release (sysctl binary layouts change)","Disable the cpu collector on hosts where ncpu cannot be trusted"],"tags":["sysctl","cpu","netbsd","bsd","platform"],"backgroundTag":"value-out-of-range","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"}