diff --git a/check_cpu b/check_cpu index 3f418ff544b0344ceb935e3eefc37e7caaf00a82..14b6a937e31be15055ed11f22a1176059b46a392 100755 --- a/check_cpu +++ b/check_cpu @@ -17,6 +17,7 @@ # 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 # 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 # ====================================================================== @@ -108,19 +109,30 @@ typeset -i iMinCpuUsageToShowProcesses=$( ph.getValueWithParam 50 p "$@") # st : time stolen from this vm by the hypervisor # top -b -n 1 | head -5 | grep "^\%Cpu" >$tmpfile # FIX read cpu from 2nd output of top -top -b -n 2 -d 0.1 | grep -i "^\%Cpu" | tail -1 >$tmpfile - -cpuUser=$( awk '{ print $2 }' $tmpfile) -cpuSystem=$( awk '{ print $4 }' $tmpfile) -cpuNice=$( awk '{ print $6 }' $tmpfile) -cpuIdle=$( awk '{ print $8 }' $tmpfile) -cpuWait=$( awk '{ print $10 }' $tmpfile) -cpuHi=$( awk '{ print $12 }' $tmpfile) -cpuSi=$( awk '{ print $14 }' $tmpfile) -cpuSt=$( awk '{ print $16 }' $tmpfile) -cpuNonIdle=$(echo 100-$cpuIdle | bc) -rm -f $tmpfile +# top -b -n 2 -d 0.1 | grep -i "^\%Cpu" | tail -1 >$tmpfile +# cpuUser=$( awk '{ print $2 }' $tmpfile) +# cpuSystem=$( awk '{ print $4 }' $tmpfile) +# cpuNice=$( awk '{ print $6 }' $tmpfile) +# cpuIdle=$( awk '{ print $8 }' $tmpfile) +# cpuWait=$( awk '{ print $10 }' $tmpfile) +# cpuHi=$( awk '{ print $12 }' $tmpfile) +# cpuSi=$( awk '{ print $14 }' $tmpfile) +# cpuSt=$( awk '{ print $16 }' $tmpfile) +# rm -f $tmpfile + +data=$( top -b -n 2 -d 0.1 | grep -i "^\%Cpu" | tail -1 | cut -f 2- -d ':' | tr ',' "\n" ) + +cpuUser=$( echo "$data" | grep "us" | awk '{ print $1 }' ) +cpuSystem=$( echo "$data" | grep "sy" | awk '{ print $1 }' ) +cpuNice=$( echo "$data" | grep "ni" | awk '{ print $1 }' ) +cpuIdle=$( echo "$data" | grep "id" | awk '{ print $1 }' ) +cpuWait=$( echo "$data" | grep "wa" | awk '{ print $1 }' ) +cpuHi=$( echo "$data" | grep "hi" | awk '{ print $1 }' ) +cpuSi=$( echo "$data" | grep "si" | awk '{ print $1 }' ) +cpuSt=$( echo "$data" | grep "st" | awk '{ print $1 }' ) + +cpuNonIdle=$(echo 100-$cpuIdle | bc) sInfo="INFO : cpu is in normal ranges." if [ "$(echo "${cpuWait} > ${iCriticalWait}" | bc)" -eq 1 ]; then