温馨提示×

centos cpustat怎样解读

小樊
41
2026-09-06 08:22:42
栏目: 智能运维

在 CentOS(以及其它 Linux 发行版)中,cpustat 通常不是系统自带命令,而是来自 sysstat 工具包(如 mpstat 的变体),或者你指的是 psutil / cpustat 工具,也可能是 perf 中的 cpustat。但最常见、最容易混淆的是以下两种:


一、sysstat 中的 mpstat(常被叫做 cpustat)

1. 安装

yum install sysstat

2. 基本用法

mpstat 1
mpstat -P ALL 1

3. 输出示例

Linux 3.10.0-1160.el7.x86_64  10/10/2024  _x86_64_  (4 CPU)

14:00:01  CPU  %usr  %nice  %sys  %iowait  %irq  %soft  %steal  %guest  %gnice  %idle
14:00:02  all   5.00   0.00   2.00     1.00   0.00   0.00     0.00    0.00    0.00  92.00
14:00:02    0   6.00   0.00   3.00     0.00   0.00   0.00     0.00    0.00    0.00  91.00

二、各字段含义(重点)

字段 含义 说明
CPU CPU 编号 all 表示平均
%usr 用户态 CPU 普通用户进程占用
%nice 低优先级用户进程 nice > 0 的进程
%sys 内核态 CPU 系统调用、调度等
%iowait IO 等待 CPU 空闲但等磁盘 IO
%irq 硬件中断
%soft 软中断 网络、网卡等
%steal 被 hypervisor 偷走 虚拟机常见
%guest 运行虚拟机 CPU
%gnice 虚拟机低优先级
%idle 空闲 CPU 越高越好

三、如何看“有没有问题”

✅ 正常情况

  • %idle 高(>70%)
  • %iowait 低(<5%)

⚠️ 可能瓶颈

  • %usr 很高 → CPU 计算密集
  • %sys 很高 → 内核/系统调用多
  • %iowait 高 → 磁盘慢
  • %steal 高 → 云主机被抢资源

四、如果是 cpustat(Go 写的工具)

有些 CentOS 上会装:

cpustat 1

输出类似:

CPU  User  Nice   Sys  Idle  IOWait  IRQ  SoftIRQ  Steal
 0    10     0     5    80      2      0     1        2

解读方式一样。


五、实用组合命令

# 看每个核
mpstat -P ALL 1

# 看进程级 CPU
top
pidstat 1

# 看中断
cat /proc/interrupts

如果你能贴出具体命令和输出,我可以直接帮你逐行解读并判断是否异常。

0