linux - How to capture CPU Idle time from Top -


i trying capture cpu idle time top. following code captures load average trying manipulate following code capture's cpu idle time.

any ideas welcome.

top -bn1 | grep load | awk '{printf "cpu load %: %.2f\n", $(nf-2)}'  above code outputs: cpu load %: 0.44 

i want change code outputs cpu idle time cpu id %: 92.9%

example top output:

top - 10:35:25 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..... ........ 

grep '%cpu(s)'

top -bn1 | grep '%cpu(s)' | awk -f',' '{printf "cpu id %: %.2f%\n", $4}' 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -