温馨提示×

如何解读debian cpustat

小樊
40
2026-10-01 17:04:23
栏目: 智能运维

在 Debian(或其他 Linux 系统)中,cpustat 通常指两种可能:

  1. cpustat 命令(来自 cpustat 软件包,由性能指标工具提供)
  2. mpstat / sar / /proc/stat 的误称(很多人把 CPU 统计工具统称为 cpustat)

下面我按最常见的 cpustat 工具来解读,同时补充系统自带方式。


一、Debian 安装 cpustat

sudo apt update
sudo apt install cpustat

运行:

sudo cpustat

二、cpustat 输出字段解读

典型输出示例:

%usr %sys %nice %idle %iowait %irq %soft %steal %guest %gnice  CPU
 12.3  5.6   0.0  80.1   1.2   0.1  0.2   0.0    0.0    0.0    all

各字段含义

字段 含义
%usr 用户态 CPU 使用率(普通进程)
%sys 内核态 CPU 使用率
%nice 低优先级用户进程
%idle 空闲 CPU
%iowait 等待 I/O 的 CPU 时间
%irq 硬中断
%soft 软中断
%steal 被虚拟机“偷走”的 CPU(云服务器常见)
%guest 运行虚拟机占用的 CPU
%gnice 低优先级虚拟机 CPU
CPU all = 总 CPU,或具体核心

三、常用 cpustat 参数

1️⃣ 每隔 1 秒刷新

sudo cpustat 1

2️⃣ 显示每个 CPU 核心

sudo cpustat -c

3️⃣ 显示指定 CPU

sudo cpustat -C 0,1

4️⃣ 显示汇总信息

sudo cpustat -s

四、如何看“系统是否繁忙”

✅ 健康状态

  • %idle > 70%
  • %iowait < 5%

⚠️ 有问题

  • %iowait 高 → 磁盘慢
  • %sys 高 → 内核或驱动问题
  • %steal 高 → 云主机资源被抢占
  • %usr 持续 90%+ → 应用 CPU 瓶颈

五、如果不想装 cpustat(系统自带)

1️⃣ mpstat(推荐)

sudo apt install sysstat
mpstat 1

2️⃣ top / htop

top
htop

3️⃣ /proc/stat(底层原理)

cat /proc/stat

六、简单判断示例

%usr 90 %idle 5

→ 某个程序在狂吃 CPU

%iowait 40 %idle 50

→ CPU 在等磁盘,不是算不过来


如果你愿意,可以把你的 cpustat 实际输出贴出来,我可以帮你逐行分析是哪类问题(CPU / IO / 虚拟化 / 进程)。

0 踩