cpustat
是一个用于监控系统 CPU 使用情况的命令行工具,它是 sysstat
包的一部分。cpustat
提供了实时的 CPU 统计信息,包括用户空间占用、系统空间占用、空闲时间等。要使用 cpustat
,首先需要确保已经安装了 sysstat
包。
在 Debian 系统上,可以使用以下命令安装 sysstat
:
sudo apt-get update
sudo apt-get install sysstat
安装完成后,可以通过以下方式使用 cpustat
命令:
cpustat
cpustat -p 0
cpustat -i 2 -c 5
cpustat -m 60
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 3.45 0.01 0.00 84.20
输出列的含义如下:
%user
:用户空间占用 CPU 的百分比%nice
:用户空间进程以 nice 值运行时占用的 CPU 百分比%system
:内核空间占用 CPU 的百分比%iowait
:等待 I/O 操作完成时占用的 CPU 百分比%steal
:虚拟机管理程序在等待物理主机分配 CPU 时间时占用的百分比%idle
:空闲 CPU 的百分比更多关于 cpustat
的信息和选项,可以查阅其手册页:
man cpustat