Skip to content
Snippets Groups Projects
Commit 72ef09a5 authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

fix syntax error on 100% idle

parent dc594b9c
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment