温馨提示×

Debian下cpustat怎么用

小樊
37
2026-07-29 13:45:41
栏目: 智能运维

在 Debian 下,cpustat 通常是 sysstat 工具包里的一个工具,用来查看 CPU 使用率统计,比 top 更偏向“采样/统计”用途。下面按常见使用场景说明。


一、安装 cpustat

1️⃣ 确认是否已安装

cpustat --version

2️⃣ 安装 sysstat

sudo apt update
sudo apt install sysstat

安装完成后,cpustat 一般位于:

/usr/bin/cpustat

二、基本用法

1️⃣ 直接运行(默认输出)

cpustat

输出示例:

  CPU  user  nice  system  idle  iowait  irq  softirq  steal  guest  guest_nice
  all   5.2   0.0     2.1  92.3     0.2  0.0      0.1    0.0    0.0         0.0

字段说明:

  • user:用户态 CPU
  • system:内核态 CPU
  • idle:空闲
  • iowait:等待 IO
  • irq / softirq:中断
  • steal:虚拟机被 hypervisor 抢占

三、常用参数

1️⃣ 指定采样间隔和次数

cpustat 1 5

含义:

  • 1 秒采样一次
  • 共采样 5 次

2️⃣ 显示所有 CPU(默认就是)

cpustat -c all

或单独查看某个 CPU:

cpustat -c 0

3️⃣ 以百分比形式显示(默认就是)

cpustat -p

4️⃣ 显示时间戳

cpustat -t

输出示例:

2026-01-15 10:30:01  all  5.1  ...

5️⃣ 输出为 CSV(适合日志/分析)

cpustat -o cpu.csv

或结合采样:

cpustat -o cpu.csv 1 10

四、常见组合示例

✅ 每秒采样一次,持续监控

cpustat 1

✅ 查看 CPU 是否瓶颈(关注 idle / iowait)

cpustat 1 10
  • idle 很低 → CPU 很忙
  • iowait 很高 → 磁盘 IO 问题
  • steal 很高 → 云主机资源被抢占

五、和 top / mpstat 的区别

工具 用途
top 实时进程级 CPU 监控
mpstat 每个 CPU 核心统计
cpustat 简洁的 CPU 使用率采样

如果你更关心 进程,用 top / htop
如果你更关心 CPU 整体趋势,用 cpustat / mpstat


六、常见问题

❓ Debian 找不到 cpustat?

确认:

dpkg -L sysstat | grep cpustat

如果确实没有,可以用:

mpstat

功能类似,Debian 一定包含。


如果你愿意,我也可以帮你:

  • 分析 cpustat 输出是否异常
  • 写个 CPU 监控脚本
  • 对比 top / mpstat / sar 哪个更适合你的场景

0