@cryptotaxi247 / netdata-1 / commits / c4d2498d7

fix: cpu system info detection on macOS (#12293)

Ilya Mashchenko committed Mar 3, 2022 at 11:03 UTC c4d2498d7617e7f90982712aa3fc03f3a9c998e7
1 file changed +15 -3
daemon/system-info.sh
+15 -3
@@ -214,6 +214,9 @@ else
214 elif [ "${KERNEL_NAME}" = FreeBSD ]; then
215 CPU_INFO_SOURCE="sysctl"
216 LCPU_COUNT="$(sysctl -n kern.smp.cpus)"
217 + elif [ "${KERNEL_NAME}" = Darwin ]; then
218 + CPU_INFO_SOURCE="sysctl"
219 + LCPU_COUNT="$(sysctl -n hw.logicalcpu)"
220 elif [ -d /sys/devices/system/cpu ]; then
221 CPU_INFO_SOURCE="sysfs"
222 # This is potentially more accurate than checking `/proc/cpuinfo`.
@@ -223,8 +226,15 @@ else
226 LCPU_COUNT="$(grep -c ^processor /proc/cpuinfo)"
227 fi
228
226 - # If we have GNU uname, we can use that to get CPU info (probably).
227 - if uname --version 2> /dev/null | grep -qF 'GNU coreutils'; then
229 + if [ "${KERNEL_NAME}" = Darwin ]; then
230 + CPU_MODEL="$(sysctl -n machdep.cpu.brand_string)"
231 + if [ "${ARCHITECTURE}" = "x86_64" ]; then
232 + CPU_VENDOR="$(sysctl -n machdep.cpu.vendor)"
233 + else
234 + CPU_VENDOR="Apple"
235 + fi
236 + echo "${CPU_INFO_SOURCE}" | grep -qv sysctl && CPU_INFO_SOURCE="${CPU_INFO_SOURCE} sysctl"
237 + elif uname --version 2> /dev/null | grep -qF 'GNU coreutils'; then
238 CPU_INFO_SOURCE="${CPU_INFO_SOURCE} uname"
239 CPU_MODEL="$(uname -p)"
240 CPU_VENDOR="$(uname -i)"
@@ -244,7 +254,9 @@ else
254 fi
255 fi
256
247 -if [ -r /sys/devices/system/cpu/cpu0/cpufreq/base_frequency ]; then
257 +if [ "${KERNEL_NAME}" = Darwin ] && [ "${ARCHITECTURE}" = "x86_64" ]; then
258 + CPU_FREQ="$(sysctl -n hw.cpufrequency)"
259 +elif [ -r /sys/devices/system/cpu/cpu0/cpufreq/base_frequency ]; then
260 if (echo "${CPU_INFO_SOURCE}" | grep -qv sysfs); then
261 CPU_INFO_SOURCE="${CPU_INFO_SOURCE} sysfs"
262 fi