在 Ubuntu 上,cpustat 通常指两种东西之一:
cpustat(sysstat 中的 mpstat / sar 相关工具)cpustat 第三方工具(如 cpustat by Colin Ian King)下面分别说明如何安装、使用和分析。
cpustatUbuntu 默认 没有名为 cpustat 的命令,通常你可能是想用:
top / htopmpstatsarvmstatpidstat如果你看到的是 cpustat 命令,一般是:
sudo apt install cpustat
cpustat(Colin Ian King 版本)sudo apt update
sudo apt install cpustat
sudo cpustat
默认输出示例:
CPU %usr %sys %nice %idle %iowait %irq %soft %steal
0 12.3 5.1 0.0 80.2 1.1 0.0 0.2 0.0
%usr:用户态 CPU 使用%sys:内核态 CPU 使用%idle:空闲%iowait:等待 IO(磁盘/网络)%irq / %soft:中断和软中断%steal:虚拟机被宿主机“偷走”的 CPUsudo cpustat -i 1 -n 5
sudo cpustat -c 0,1
sudo cpustat -p
mpstat(sysstat)sudo apt install sysstat
mpstat 1
分析重点:
%usr 高 → 应用层问题%sys 高 → 内核/系统调用多%iowait 高 → 磁盘瓶颈%steal 高 → 云主机资源争抢sar(历史分析)sar -u 1 3
查看历史:
sar -u -f /var/log/sysstat/saXX
htop(交互式)sudo apt install htop
htop
htop 看是哪个进程pidstat -u 1 看进程级perf top(高级)%iowaitiostat -x 1%steal| 工具 | 适合场景 |
|---|---|
| cpustat | 快速看 CPU 细分 |
| mpstat | 实时监控 |
| sar | 历史分析 |
| htop | 交互排查 |
| pidstat | 进程级 CPU |
如果你愿意,可以贴一段 cpustat 或 mpstat 的输出,我可以帮你具体解读是哪类瓶颈。