在 CentOS 系统中,cpustat 通常是 sysstat 工具包的一部分,用于查看 CPU 的使用情况。下面是详细的使用说明,从安装到常见用法。
which cpustat
sudo yum install -y sysstat
CentOS 7/8 默认仓库中都有 sysstat
cpustat
输出示例:
CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle
all 5.2 0.0 1.3 0.2 0.0 0.1 0.0 0.0 0.0 93.2
字段说明:
%usr:用户态 CPU 使用率%sys:内核态 CPU 使用率%idle:空闲 CPU%iowait:IO 等待占用的 CPUcpustat 1 5
含义:
cpustat -c
或(不同版本可能):
mpstat -P ALL
cpustat -C 0
cpustat -u
watch -n 1 cpustat
在很多 CentOS 系统中:
cpustat 实际上是 mpstat 的别名或简化版mpstat
mpstat 1
mpstat -P ALL 1
示例:
mpstat -P ALL 1 3
mpstat 1
关注 %iowait
mpstat -P ALL 1
mpstat -I ALL
✅ 解决方案:
sudo yum install sysstat
cpustat/mpstat 统计的是 CPU 时间占比top 是实时快照,略有差异# 安装
sudo yum install -y sysstat
# 基本使用
cpustat
cpustat 1 5
# 每个 CPU 单独显示
mpstat -P ALL 1
# 持续监控
watch -n 1 cpustat
如果你愿意,我也可以:
cpustat 输出sar 做历史 CPU 分析top / htop / pidstat 一起诊断高 CPU 问题