From dc242d3631cf33d78561f706ad4b21e55f305ec7 Mon Sep 17 00:00:00 2001 From: Lars Kruse Date: Sat, 8 Feb 2020 03:35:19 +0100 Subject: [PATCH] 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. --- plugins/cpu | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/cpu b/plugins/cpu index 53f64fc..9aabd37 100644 --- a/plugins/cpu +++ b/plugins/cpu @@ -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))