我试图从TOP捕获CPU空闲时间。 以下代码捕获Load Average 我试图操纵以下代码,以便捕获CPU的空闲时间。
欢迎任何想法。
top -bn1 | grep load | awk '{printf "CPU load %: %.2f\n", $(NF-2)}'
The Above Code Outputs: CPU load %: 0.44
我想更改代码,以便输出CPU空闲时间 CPU Id%:92.9%
示例顶部输出:
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.....
........
答案 0 :(得分:0)
grep for'%Cpu(s)'
top -bn1 | grep '%Cpu(s)' | awk -F',' '{printf "CPU id %: %.2f%\n", $4}'