温馨提示×

centos cpustat怎么监控

小樊
46
2026-07-20 21:33:18
栏目: 智能运维

CentOS 上,cpustat 并不是系统默认自带的命令,它通常来自 sysstat 工具包,或者你是想用 mpstat / sar / top / htop 等工具来监控 CPU。下面分几种常见情况说明。


一、确认 cpustat 是否存在

1️⃣ 先检查是否已安装

which cpustat

如果没有,常见情况有两种:


二、方式一:使用 sysstat(推荐)

1️⃣ 安装 sysstat

yum install -y sysstat

2️⃣ 使用 mpstat(最常用)

mpstat 是 sysstat 中用来监控 CPU 的核心工具。

查看所有 CPU

mpstat -P ALL

每 2 秒刷新一次

mpstat -P ALL 2

每 2 秒刷新,共 5 次

mpstat -P ALL 2 5

输出字段说明

字段 含义
%usr 用户态 CPU
%sys 内核态 CPU
%iowait IO 等待
%idle 空闲

三、方式二:cpustat(来自 Go 工具,非默认)

如果你看到别人用 cpustat 命令,可能是 tools 项目中的 cpustat(如 github.com/uber-common/cpustat)。

1️⃣ 安装(需要 Go)

yum install -y epel-release
yum install -y golang

然后:

go get github.com/uber-common/cpustat

2️⃣ 使用

cpustat

⚠️ 注意:

  • 该工具 不是 CentOS 官方工具
  • 需要 root 权限
  • 更适合高级性能分析

四、方式三:用 sar 做历史监控(最专业)

1️⃣ 启用 sysstat

systemctl enable sysstat
systemctl start sysstat

2️⃣ 实时查看 CPU

sar -u 1

3️⃣ 查看历史 CPU(例如今天)

sar -u

五、方式四:简单实时查看(top / htop)

top

top

htop(更友好,需安装)

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 飙高、进程级、历史趋势、容器、云服务器),我可以给你更精确的命令。

0