Issue
I am trying to capture the CPU idle time (id
) from top
.
The following code captures Load Average and I am trying to manipulate the following code so that it capture's CPU idle time.
Any ideas welcome.
top -bn1 | grep load | awk '{printf "CPU load %: %.2f\n", $(NF-2)}'
The above code outputs:
CPU load %: 0.44
I want to change the code so that it outputs CPU idle time
CPU Id %: 92.9%
Example Top output:
top - 10:35:25 up 1 day, 16:06, 5 users, load average: 0.24, 0.16, 0.15
Tasks: 210 total, 2 running, 198 sleeping, 10 stopped, 0 zombie
%Cpu(s): 2.2 us, 0.2 sy, 4.7 ni, 92.9 id, 0.0 wa, 0.0 hi, 0.0 si, 0.1 st
KiB Mem: 16433064 total, 1353396 used, 15079668 free, 180944 buffers
KiB Swap: 0 total, 0 used, 0 free. 700468 cached Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
24293 ubuntu 30 10 32828 2576 1608 S 19.3 0.0 0:25.30 fiberlamp
2173 ubuntu 20 0 51200 16496 4952 S 9.3 0.1 263:34.18 Xvnc4
12648 ubuntu 20 0 23668 1732 1180 R 0.3 0.0 0:04.25 top
...
Solution
grep for '%Cpu(s)'
top -bn1 | grep '%Cpu(s)' | awk -F',' '{printf "CPU id %: %.2f%\n", $4}'
Answered By - RenBrian Answer Checked By - David Goodson (WPSolving Volunteer)