@cryptotaxi247 / netdata-1 / commits / e3a1087b9

fix: returning 0 for CPU frequency when unknown (#12323)

Ilya Mashchenko committed Mar 4, 2022 at 20:18 UTC e3a1087b9f5200e670a22bb7af54573d40167416
1 file changed +6 -5
daemon/system-info.sh
+6 -5
@@ -196,13 +196,14 @@ if [ -n "${lscpu}" ] && lscpu > /dev/null 2>&1; then
196 LCPU_COUNT="$(echo "${lscpu_output}" | grep "^CPU(s):" | cut -f 2 -d ':' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
197 CPU_VENDOR="$(echo "${lscpu_output}" | grep "^Vendor ID:" | cut -f 2 -d ':' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
198 CPU_MODEL="$(echo "${lscpu_output}" | grep "^Model name:" | cut -f 2 -d ':' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
199 - possible_cpu_freq="$(echo "${lscpu_output}" | grep -F "CPU max MHz:" | cut -f 2 -d ':' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' | grep -o '^[0-9]*') MHz"
200 - if [ "${possible_cpu_freq}" = " MHz" ]; then
201 - possible_cpu_freq="$(echo "${lscpu_output}" | grep -F "CPU MHz:" | cut -f 2 -d ':' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' | grep -o '^[0-9]*') MHz"
199 + possible_cpu_freq="$(echo "${lscpu_output}" | grep -F "CPU max MHz:" | cut -f 2 -d ':' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' | grep -o '^[0-9]*')"
200 + if [ -z "$possible_cpu_freq" ]; then
201 + possible_cpu_freq="$(echo "${lscpu_output}" | grep -F "CPU MHz:" | cut -f 2 -d ':' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' | grep -o '^[0-9]*')"
202 fi
203 - if [ "${possible_cpu_freq}" = " MHz" ]; then
204 - possible_cpu_freq="$(echo "${lscpu_output}" | grep "^Model name:" | grep -Eo "[0-9\.]+GHz" | grep -o "^[0-9\.]*" | awk '{print int($0*1000)}') MHz"
203 + if [ -z "$possible_cpu_freq" ]; then
204 + possible_cpu_freq="$(echo "${lscpu_output}" | grep "^Model name:" | grep -Eo "[0-9\.]+GHz" | grep -o "^[0-9\.]*" | awk '{print int($0*1000)}')"
205 fi
206 + [ -n "$possible_cpu_freq" ] && possible_cpu_freq="${possible_cpu_freq} MHz"
207 elif [ -n "${dmidecode}" ] && dmidecode -t processor > /dev/null 2>&1; then
208 dmidecode_output="$(${dmidecode} -t processor 2> /dev/null)"
209 CPU_INFO_SOURCE="dmidecode"