@cryptotaxi247 / netdata-1 / commits / 22029fb4c

fix(freebsd): CPU frequency detection returns unknown causing NaN display (#21658)

Costa Tsaousis committed Jan 28, 2026 at 08:25 UTC 22029fb4cc82265358d173b260ad32ab3f472059
1 file changed +11 -5
src/daemon/system-info.sh
+11 -5
@@ -256,19 +256,25 @@ elif [ -n "${dmidecode}" ] && dmidecode -t processor >/dev/null 2>&1; then
256 CPU_MODEL="$(echo "${dmidecode_output}" | grep -F "Version:" | cut -f 2 -d ':' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
257 possible_cpu_freq="$(echo "${dmidecode_output}" | grep -F "Current Speed:" | cut -f 2 -d ':' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
258 else
259 - if [ -n "${nproc}" ]; then
260 - CPU_INFO_SOURCE="nproc"
261 - LCPU_COUNT="$(${nproc})"
262 - elif [ "${KERNEL_NAME}" = FreeBSD ]; then
259 + # Check OS-specific methods FIRST, then fall back to generic methods
260 + if [ "${KERNEL_NAME}" = FreeBSD ]; then
261 CPU_INFO_SOURCE="sysctl"
262 LCPU_COUNT="$(sysctl -n kern.smp.cpus)"
265 - if ! possible_cpu_freq=$(sysctl -n machdep.tsc_freq 2>/dev/null); then
263 + # Try dev.cpu.0.freq first (what freebsd.plugin uses, returns MHz)
264 + if possible_cpu_freq=$(sysctl -n dev.cpu.0.freq 2>/dev/null); then
265 + possible_cpu_freq="${possible_cpu_freq} MHz"
266 + # Fallback to machdep.tsc_freq (returns Hz, no unit suffix needed)
267 + elif ! possible_cpu_freq=$(sysctl -n machdep.tsc_freq 2>/dev/null); then
268 + # Last resort: parse hw.model for GHz values
269 possible_cpu_freq=$(sysctl -n hw.model 2>/dev/null | grep -Eo "[0-9\.]+GHz" | grep -o "^[0-9\.]*" | awk '{print int($0*1000)}')
270 [ -n "$possible_cpu_freq" ] && possible_cpu_freq="${possible_cpu_freq} MHz"
271 fi
272 elif [ "${KERNEL_NAME}" = Darwin ]; then
273 CPU_INFO_SOURCE="sysctl"
274 LCPU_COUNT="$(sysctl -n hw.logicalcpu)"
275 + elif [ -n "${nproc}" ]; then
276 + CPU_INFO_SOURCE="nproc"
277 + LCPU_COUNT="$(${nproc})"
278 elif [ -d /sys/devices/system/cpu ]; then
279 CPU_INFO_SOURCE="sysfs"
280 # This is potentially more accurate than checking `/proc/cpuinfo`.