From 288d9082a8e22e028f289281be1e1afb02918811 Mon Sep 17 00:00:00 2001 From: "Hahn Axel (hahn)" <axel.hahn@iml.unibe.ch> Date: Wed, 9 Mar 2022 16:41:38 +0100 Subject: [PATCH] v1.7: show most consuming processes if usage is > nn % --- check_cpu | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/check_cpu b/check_cpu index a91949c..9e6687b 100755 --- a/check_cpu +++ b/check_cpu @@ -15,12 +15,15 @@ # 2021-02-10 v1.4 <axel.hahn@iml.unibe.ch> added critical io wait # 2021-10-28 v1.5 <axel.hahn@iml.unibe.ch> Use 2nd update of top # 2021-12-10 v1.6 <axel.hahn@iml.unibe.ch> show processes with status D to find cpu waits +# 2022-03-09 v1.7 <axel.hahn@iml.unibe.ch> show most cpu intensive processes # ====================================================================== . `dirname $0`/inc_pluginfunctions tmpfile=/tmp/check_cpu_$$ +iMinCpuUsageToShowProcesses=30 + # ---------------------------------------------------------------------- # functions # ---------------------------------------------------------------------- @@ -29,7 +32,7 @@ function showHelp(){ cat <<EOF ______________________________________________________________________ -CHECK_CPU check cpu usage and cpu wait v1.6 +CHECK_CPU check cpu usage and cpu wait v1.7 (c) Institute for Medical Education - Univerity of Bern Licence: GNU GPL 3 @@ -135,6 +138,14 @@ echo "$plist" | grep "[0-9]" >/dev/null \ && echo "For analysis of cpu waits - processes with status D:" \ && echo "$plist" +# v1.7: show most consuming processes if usage is > nn % +typeset -i iUsed=$( echo $cpuNonIdle | cut -f 1 -d '.' ) +if [ $iUsed -gt $iMinCpuUsageToShowProcesses ]; then + echo + echo "CPU usage is higher $iMinCpuUsageToShowProcesses percent ... showing most consuming processes:" + ps aux | head -1; ps aux | sort -nrk 3,3 | head -n 5 +fi + echo " Limits: usage warn at ${iWarnLimit} .. critical at ${iCriticalLimit} .. io wait limit ${iCriticalWait} $sInfo -- GitLab