如何从命令行获取 CPU 利用率、MAC 中的 RAM 利用率

How to get CPU utilisation, RAM utilisation in MAC from commandline

我知道使用 Activity 监视器我们可以看到 CPU utilisation.But 我想通过脚本获取远程系统的这些信息。 top 命令对我没有帮助。请评论我以任何其他方式获得它。

top 日志模式的异议是什么?

top -l 1 | grep -E "^CPU|^Phys"

CPU usage: 3.27% user, 14.75% sys, 81.96% idle 
PhysMem: 5807M used (1458M wired), 10G unused.

或使用sysctl

sysctl vm.loadavg
vm.loadavg: { 1.31 1.85 2.00 }

或使用vm_stat

vm_stat
Mach Virtual Memory Statistics: (page size of 4096 bytes)
Pages free:                                3569.
Pages active:                            832177.
Pages inactive:                          283212.
Pages speculative:                      2699727.
Pages throttled:                              0.
Pages wired down:                        372883.