cpustat 是一个用于监控 CPU 性能的命令行工具,它是 sysstat 软件包的一部分。要使用 cpustat 监控 CPU 性能,请按照以下步骤操作:
sysstat 软件包。在基于 Debian 的系统(如 Ubuntu)上,可以使用以下命令安装:sudo apt-get update
sudo apt-get install sysstat
在基于 RHEL 的系统(如 CentOS、Fedora)上,可以使用以下命令安装:
sudo yum install sysstat
cpustat 命令来查看 CPU 性能。默认情况下,cpustat 会显示系统的 CPU 使用情况,包括用户空间、系统空间、空闲时间等。例如:$ cpustat
Linux 5.4.0-42-generic (hostname) 05/01/2021 _x86_64_ (4 CPU)
avg-cpu: %user %nice %system %iowait %steal %idle
12.34 0.00 1.23 0.01 0.00 86.42
cpustat 还提供了许多选项,以便根据需要定制输出。例如,可以使用 -P 选项查看每个 CPU 的详细信息:$ cpustat -P ALL
Linux 5.4.0-42-generic (hostname) 05/01/2021 _x86_64_ (4 CPU)
avg-cpu: %user %nice %system %iowait %steal %idle
12.34 0.00 1.23 0.01 0.00 86.42
CPU %user %nice %system %iowait %steal %idle
CPU0 10.12 0.00 1.11 0.02 0.00 88.75
CPU1 15.43 0.00 1.34 0.01 0.00 83.22
CPU2 11.22 0.00 1.00 0.03 0.00 87.75
CPU3 12.34 0.00 1.23 0.01 0.00 86.42
-c 选项后跟刷新间隔(以秒为单位)和要显示的次数。例如,每隔 2 秒显示一次 CPU 性能,共显示 5 次:$ cpustat -c 2 5
Linux 5.4.0-42-generic (hostname) 05/01/2021 _x86_64_ (4 CPU)
avg-cpu: %user %nice %system %iowait %steal %idle
12.34 0.00 1.23 0.01 0.00 86.42
avg-cpu: %user %nice %system %iowait %steal %idle
10.12 0.00 1.11 0.02 0.00 88.75
avg-cpu: %user %nice %system %iowait %steal %idle
11.22 0.00 1.00 0.03 0.00 87.75
avg-cpu: %user %nice %system %iowait %steal %idle
12.34 0.00 1.23 0.01 0.00 86.42
avg-cpu: %user %nice %system %iowait %steal %idle
10.56 0.00 1.19 0.02 0.00 88.23
这些选项可以根据需要进行组合,以便更好地了解系统的 CPU 性能。更多关于 cpustat 的信息和选项,请参阅其手册页(通过运行 man cpustat)。