-2

I understood that top and htop give a lot of info in real-time on the server status. But what really gives me the total CPU of the server? can I rely on the id column from top command:

%Cpu(s):  1.9 us,  0.7 sy,  0.0 ni, 92.2 id,  5.2 wa,  0.0 hi,  0.1 si,  0.0 st

For example, from the above example, does that total CPU is 92.2% out of 100%? and then it can be calculated this way:

(top -b -n2 -p 1 | fgrep "Cpu(s)" | tail -1 | awk -F'id,' -v prefix="$prefix" '{ split($1, vs, ","); v=vs[length(vs)]; sub("%", "", v); printf "%s%.1f%%\n", prefix, 100 - v }')

我在天马彩票平台输了三十万or from this link where the calculation suggested there is:

awk '{u=$2+$4; t=$2+$4+$5; if (NR==1){u1=u; t1=t;} else print ($2+$4-u1) * 100 / (t-t1) "%"; }' \
<(grep 'cpu ' /proc/stat) <(sleep 1;grep 'cpu ' /proc/stat)

or:

top -bn1 | grep "Cpu(s)" | \
           sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | \
           awk '{print 100 - $1"%"}'

or:

mpstat | awk '$3 ~ /CPU/ { for(i=1;i<=NF;i++) { if ($i ~ /%idle/) field=i } } $3 ~ /all/ { print 100 - $field }'

also, what suppose to be the ideal value which we don't want to pass?

  • – Qasim Feb 26 at 0:03
  • tnx, but those are methods for getting CPU, but it doesn't answer the question – arielma Feb 26 at 0:06
  • Ideal value depends... for interactive use, 0. For batch usage, around 70% × CPUs. – vonbrand Feb 26 at 18:25

Your Answer

By clicking “Post Your Answer”, you agree to our , and

Browse other questions tagged or ask your own question.