need to get average idle time using mpstat
I want to get average idle time of the server using mpstat. The problem I am having is %idle is not in same columns in all the versions of linux.
example 1: Quote:
Quote:
Quote:
Quote:
Quote:
|
Is it always the last word of the last line?
Code:
mpstat 1 2 | tr '\n' ' ' | tail -n 1 |
Hi Guttorm,
My requirement is to get only the details of %idle column. no all the output. Thanks. |
I meant to change every space to newline, to only get the last word in the file. But my code was incorrect, changing newlines to spaces instead of the other way around.
Code:
mpstat 1 2 | tr ' ' '\n' | tail -n 1 Code:
awk '{print $NF}' |
My problem is idle column varies with OS version so I am trying for generalized solution to get %idle column irrespective of the OS version. the solution I tried is working fine but failing in Average column as number of columns differ.
|
So test for "Average" and use $(i-1). But seeing as how that what you want, why not just use it ?.
There is also no need for grep - you can do that elimination in your awk. |
Thanks it worked I was trying the same but was having syntax error thanks.
Code:
mpstat 1 2 | egrep -v '^Linux|^$' | awk -v c="%idle" 'NR==1 {for (i=1; i<=NF; i++) if ($i==c) break}''{print $(i-1)}' | tail -1 |
All times are GMT -5. The time now is 11:03 PM. |