温馨提示×

centos cpustat为何报错

小樊
47
2026-07-20 21:26:19
栏目: 智能运维

cpustat 在 CentOS 上报错,通常不是命令本身的问题,而是没装、装错、或运行环境不对。下面按常见原因给你排查。


1️⃣ cpustat 不是 CentOS 自带命令

CentOS 默认没有 cpustat,它来自 sysstatpcp 相关工具包,或者来自 Go 写的 cpustat(如 github.com/uber-common/cpustat)。

常见报错

-bash: cpustat: command not found

解决

✅ 情况一:你要的是 sysstat 里的工具

其实你可能想用的是 mpstat / sar / iostat,而不是 cpustat

yum install -y sysstat
mpstat

✅ 情况二:你要的是 Uber 的 cpustat

这是 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

2️⃣ 权限不足(很常见)

cpustat 需要读取 /proc 和系统性能数据

报错示例

open /proc/stat: permission denied

解决

sudo cpustat

sudo ./cpustat

3️⃣ 内核 / proc 文件系统问题

报错示例

cannot read /proc/stat
/proc is not mounted

检查

ls /proc/stat

解决

  • 确认系统不是容器(Docker / LXC)被限制
  • 容器里很多 cpustat 工具 无法使用

4️⃣ CentOS 版本问题

CentOS 版本 说明
CentOS 7 sysstat 正常
CentOS 8 已 EOL,yum 可能失败
CentOS Stream 可能缺少某些包

如果是 CentOS 8 / Stream,建议:

dnf install sysstat

5️⃣ 你其实不需要 cpustat(推荐替代)

如果你只是想看 CPU 使用率,更推荐:

top
htop
vmstat 1
mpstat -P ALL 1
sar -u 1 5

✅ 快速判断你该用哪个

需求 建议
看 CPU 使用率 mpstat
看进程 CPU top / htop
看历史 CPU sar
高级性能分析 pcp / perf

如果你愿意,可以把 完整报错信息贴出来(包括 CentOS 版本),我可以直接帮你定位是哪一类问题。

0