在 Debian 系统中,cpustat 通常来自 sysstat 工具包。下面按常见情况说明如何查看和使用它。
先检查是否存在:
which cpustat
如果提示找不到,说明尚未安装。
sudo apt update
sudo apt install sysstat
安装完成后即可使用 cpustat。
cpustat
默认会显示 每个 CPU 的使用情况,例如:
CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle
all 12.3 0.0 3.1 0.5 0.0 0.2 0.0 0.0 0.0 83.9
cpustat 1 5
含义:
cpustat -c
或:
mpstat -P ALL
(mpstat 也是 sysstat 里的工具,信息更详细)
cpustat -e
可显示中断、上下文切换等扩展信息(取决于版本)。
有些 Debian 版本或最小化安装可能不包含 cpustat,可以用以下替代方案:
sudo apt install sysstat
mpstat -P ALL 1
top
htop
cat /proc/stat
| 需求 | 命令 |
|---|---|
| 安装 cpustat | sudo apt install sysstat |
| 实时查看 CPU | cpustat |
| 定时采样 | cpustat 1 5 |
| 查看每个核心 | mpstat -P ALL |
| 更易读 | htop |
如果你是想 排查 CPU 高负载、做性能分析,或服务器监控,可以告诉我具体场景,我可以给你更针对性的用法。