温馨提示×

如何用cpustat测debian

小樊
43
2026-10-07 12:59:07
栏目: 智能运维

在 Debian 系统上,cpustat 通常不是系统默认安装的工具。它一般来自 perf-tools 或 sysstat 包中的不同实现(常见的是 cpustat by Brendan Gregg 的 perf-tools,或者 Ubuntu/Debian 仓库里的 cpustat 包)。下面我分情况说明如何在 Debian 上使用 cpustat。


一、确认你要用的是哪个 cpustat

1. sysstat 中的 cpustat?

实际上 sysstat 包里没有叫 cpustat 的命令,相关的是:

  • mpstat
  • sar

如果你只是想看 CPU 利用率,可用:

sudo apt install sysstat
mpstat 1

二、安装并使用 Brendan Gregg 的 cpustat(perf-tools)

这是最常见的 cpustat,基于 perf。

1. 安装依赖

sudo apt update
sudo apt install linux-tools-common linux-tools-generic perf

2. 下载 cpustat

git clone https://github.com/brendangregg/perf-tools.git
cd perf-tools

3. 运行 cpustat

sudo ./cpustat 1

含义:每 1 秒采样一次 CPU 使用详情。

示例输出字段:

  • us 用户态
  • sy 内核态
  • ni nice
  • id 空闲
  • wa IO 等待
  • hi 硬中断
  • si 软中断

三、使用 Debian/Ubuntu 仓库中的 cpustat(如果你指的是这个)

某些 Debian 衍生版提供独立 cpustat 包:

sudo apt install cpustat

运行:

sudo cpustat 1

功能类似,用于周期性显示 CPU 统计。


四、常见问题

1. 提示没有 perf

sudo apt install linux-tools-$(uname -r)

2. 权限问题

cpustat 通常需要 root:

sudo cpustat 1

3. 只看某个 CPU

sudo cpustat -C 0 1

五、替代方案(Debian 常用)

如果你只是排查性能:

top
htop
mpstat 1
sar -u 1

如果你能告诉我:

  • 你是 想测整体 CPU 使用率 还是 按进程/线程分析
  • 你的 Debian 版本(cat /etc/os-release)

我可以给你更精确的命令示例。

0 踩