温馨提示×

debian cpustat怎样解读

小樊
32
2026-09-16 19:54:15
栏目: 智能运维

在 Debian(以及大多数 Linux 发行版)中,cpustat 通常指两种东西之一:

  1. cpustat 命令(来自 sysstat 包或 cpustat 工具)
  2. /proc/stat 中的 CPU 统计信息(常被误称为 cpustat)

下面分别说明如何解读。


一、使用 cpustat 命令(推荐方式)

安装

sudo apt update
sudo apt install cpustat

或(更常见)

sudo apt install sysstat

基本用法

cpustat 1

表示每 1 秒刷新一次。

输出示例

Linux 6.1.0 (debian)   2026-01-21

05:10:01  CPU  %usr  %sys  %nice  %idle  %iowait  %irq  %soft  %steal
05:10:02  all   12.3   4.5    0.0    82.1     0.8    0.1   0.2     0.0
05:10:02    0   20.0   5.0    0.0    75.0     0.0    0.0   0.0     0.0

字段含义

字段 含义
%usr 用户态 CPU 使用率(普通程序)
%sys 内核态 CPU 使用率(系统调用等)
%nice 低优先级用户进程占用
%idle 空闲 CPU
%iowait 等待 I/O 的 CPU 时间
%irq 硬件中断
%soft 软件中断
%steal 被虚拟机偷走的 CPU(云服务器常见)

解读原则

  • %idle 很低 → CPU 繁忙
  • %iowait 高 → 磁盘/网络 I/O 瓶颈
  • %sys 高 → 内核或驱动问题
  • %steal 高 → 宿主机资源争抢

二、/proc/stat(底层 CPU 统计)

cat /proc/stat

示例:

cpu  1000 50 300 5000 200 0 10 0

字段顺序:

user nice system idle iowait irq softirq steal

⚠️ 这些是累计节拍数(jiffies),不是百分比。

简单计算 CPU 使用率

total = user + nice + system + idle + iowait + irq + softirq + steal
usage = (total - idle) / total * 100%

三、常见场景解读

1️⃣ CPU 满负荷

%usr + %sys ≈ 100%
%idle ≈ 0

→ 需要优化程序或扩容

2️⃣ 系统卡但 CPU 不高

%iowait 很高

→ 磁盘慢 / 数据库压力大

3️⃣ 虚拟机卡顿

%steal 很高

→ 云厂商超卖严重


四、和 top / htop 的关系

  • cpustat:看整体趋势
  • top / htop:看哪个进程占用

如果你愿意,可以把你的 cpustat 实际输出贴出来,我可以帮你逐行分析。

0