cpustat 在 CentOS 上报错,通常不是命令本身的问题,而是没装、装错、或运行环境不对。下面按常见原因给你排查。
cpustat 不是 CentOS 自带命令CentOS 默认没有 cpustat,它来自 sysstat 或 pcp 相关工具包,或者来自 Go 写的 cpustat(如 github.com/uber-common/cpustat)。
-bash: cpustat: command not found
其实你可能想用的是 mpstat / sar / iostat,而不是 cpustat
yum install -y sysstat
mpstat
这是 Go 写的工具,不是系统自带
# 需要 go 环境
go install github.com/uber-common/cpustat@latest
或下载二进制:
wget https://github.com/uber-common/cpustat/releases/download/vX.X.X/cpustat
chmod +x cpustat
./cpustat
cpustat 需要读取 /proc 和系统性能数据
open /proc/stat: permission denied
sudo cpustat
或
sudo ./cpustat
cannot read /proc/stat
/proc is not mounted
ls /proc/stat
cpustat 工具 无法使用| CentOS 版本 | 说明 |
|---|---|
| CentOS 7 | sysstat 正常 |
| CentOS 8 | 已 EOL,yum 可能失败 |
| CentOS Stream | 可能缺少某些包 |
如果是 CentOS 8 / Stream,建议:
dnf install sysstat
如果你只是想看 CPU 使用率,更推荐:
top
htop
vmstat 1
mpstat -P ALL 1
sar -u 1 5
| 需求 | 建议 |
|---|---|
| 看 CPU 使用率 | mpstat |
| 看进程 CPU | top / htop |
| 看历史 CPU | sar |
| 高级性能分析 | pcp / perf |
如果你愿意,可以把 完整报错信息贴出来(包括 CentOS 版本),我可以直接帮你定位是哪一类问题。