Plugin cpu: fix handling of more than ten CPUs

Previously only CPU entries with a single digit (0..9) were parsed.
The improved regular expression simplifies the calculation of the CPU
count, since the combined entry ("cpu" without digits) is skipped.
This commit is contained in:
Lars Kruse 2020-02-08 03:35:19 +01:00
parent 14251d6791
commit dc242d3631
1 changed files with 2 additions and 2 deletions

View File

@ -3,8 +3,8 @@ config_cpu() {
if grep '^cpu \{1,\}[0-9]\{1,\} \{1,\}[0-9]\{1,\} \{1,\}[0-9]\{1,\} \{1,\}[0-9]\{1,\} \{1,\}[0-9]\{1,\} \{1,\}[0-9]\{1,\} \{1,\}[0-9]\{1,\}' /proc/stat >/dev/null 2>&1; then
extinfo="iowait irq softirq"
fi
NCPU=$(($(grep '^cpu. ' /proc/stat | wc -l) - 1))
if [ $NCPU = 0 ]; then NCPU=1; fi
# shellcheck disable=SC2126
NCPU=$(grep '^cpu[0-9]\+ ' /proc/stat | wc -l)
PERCENT=$(($NCPU * 100))
graphlimit=$PERCENT
SYSWARNING=$(($PERCENT * 30 / 100))