cpustat 是一个用于显示 CPU 使用情况的工具,它是 sysstat 软件包的一部分。在 Debian 系统中,你可以通过运行 sudo apt-get install sysstat 来安装它(如果尚未安装)。
cpustat 的输出提供了关于 CPU 使用情况的详细信息,包括用户空间进程、系统空间进程、空闲时间等的使用情况。以下是 cpustat 输出的一些关键部分的解读:
Linux 5.4.0-42-generic (hostname) 08/01/2023 _x86_64_ (4 CPU)
avg-cpu: %user %nice %system %iowait %steal %idle
12.34 0.00 2.34 0.12 0.00 85.20
%user: 用户空间进程消耗的 CPU 时间百分比。%nice: 优先级调整过的用户空间进程消耗的 CPU 时间百分比。%system: 内核空间进程消耗的 CPU 时间百分比。%iowait: CPU 等待 I/O 操作完成的时间百分比。%steal: 在虚拟化环境中,CPU 被其他虚拟机占用的时间百分比。%idle: CPU 空闲时间百分比。如果你运行 cpustat -P ALL,它会显示每个 CPU 的详细使用情况:
Linux 5.4.0-42-generic (hostname) 08/01/2023 _x86_64_ (4 CPU)
avg-cpu: %user %nice %system %iowait %steal %idle
12.34 0.00 2.34 0.12 0.00 85.20
CPU %usr %sys %iowait %irq %soft %steal %guest %gnice %idle
0 12.34 2.34 0.12 0.00 0.00 0.00 0.00 0.00 85.20
1 11.56 2.78 0.15 0.00 0.00 0.00 0.00 0.00 85.51
2 13.45 2.12 0.10 0.00 0.00 0.00 0.00 0.00 84.33
3 10.98 2.56 0.18 0.00 0.00 0.00 0.00 0.00 86.38
%iowait 的值高可能表示磁盘 I/O 瓶颈。%steal 的值高可能表示虚拟化环境中资源争用。%idle 的值低可能表示 CPU 资源紧张。通过分析这些数据,你可以更好地理解系统的性能瓶颈和资源使用情况。