在 CentOS 上,cpustat 并不是系统默认自带的命令,它通常来自 sysstat 工具包,或者你是想用 mpstat / sar / top / htop 等工具来监控 CPU。下面分几种常见情况说明。
which cpustat
如果没有,常见情况有两种:
yum install -y sysstat
mpstat 是 sysstat 中用来监控 CPU 的核心工具。
mpstat -P ALL
mpstat -P ALL 2
mpstat -P ALL 2 5
| 字段 | 含义 |
|---|---|
| %usr | 用户态 CPU |
| %sys | 内核态 CPU |
| %iowait | IO 等待 |
| %idle | 空闲 |
如果你看到别人用 cpustat 命令,可能是 tools 项目中的 cpustat(如 github.com/uber-common/cpustat)。
yum install -y epel-release
yum install -y golang
然后:
go get github.com/uber-common/cpustat
cpustat
⚠️ 注意:
systemctl enable sysstat
systemctl start sysstat
sar -u 1
sar -u
top
yum install -y epel-release
yum install -y htop
htop
✅ 日常监控
mpstat -P ALL 2
✅ 历史分析
sar -u
✅ 实时查看
top
| 工具 | 用途 |
|---|---|
| mpstat | 实时 CPU 使用率 |
| sar | 历史 CPU 分析 |
| top / htop | 快速查看 |
| cpustat | 高级分析(非默认) |
如果你能贴出 你是想监控什么场景(比如:CPU 飙高、进程级、历史趋势、容器、云服务器),我可以给你更精确的命令。