From e75eb71bfa981bfb401bb83aaef9be576d412cdf Mon Sep 17 00:00:00 2001 From: "Hahn Axel (hahn)" <axel.hahn@iml.unibe.ch> Date: Thu, 14 Apr 2022 14:31:19 +0200 Subject: [PATCH] show consuming cpu processes with top and ps --- check_cpu | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/check_cpu b/check_cpu index 67a6479..bbea1f2 100755 --- a/check_cpu +++ b/check_cpu @@ -18,6 +18,7 @@ # 2022-03-09 v1.7 <axel.hahn@iml.unibe.ch> show most cpu intensive processes # 2022-03-10 v1.8 <axel.hahn@iml.unibe.ch> add cli param -p; update help # 2022-03-22 v1.9 <axel.hahn@iml.unibe.ch> fix syntax error on 100% idle +# 2022-04-14 v1.10 <axel.hahn@iml.unibe.ch> show consuming cpu processes with top and ps # ====================================================================== @@ -155,8 +156,16 @@ echo "$plist" | grep "[0-9]" >/dev/null \ 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:" + echo "CPU usage is higher $iMinCpuUsageToShowProcesses percent ... showing most consuming processes" + echo "output of top :" + topout=$( top -b -n 1 -d 0.1 ) + typeset -i iStart=$( echo "$topout" | grep -n "PID.*USER" | cut -f 1 -d ':' ) + typeset -i iEnd=$iStart+5 + echo "$topout" | sed -n "${iStart},${iEnd}p" + echo + echo "output of ps:" ps aux | head -1; ps aux | sort -nrk 3,3 | head -n 5 + echo fi echo " -- GitLab