温馨提示×

cpustat怎么测debiancpu

小樊
45
2026-10-04 15:34:08
栏目: 智能运维

在 Debian 上,cpustat 通常来自 sysstat 工具集(命令是 mpstat 的“兄弟”),也可以是 Go 写的 cpustat(by tools/perf 之类)。我先分两种情况说明,最常见的是 sysstat 里的 cpustat / mpstat。


一、Debian 使用 sysstat 的 cpustat(推荐)

1. 安装

sudo apt update
sudo apt install sysstat

2. 启用统计(可选但建议)

sudo systemctl enable sysstat
sudo systemctl start sysstat

3. 基本用法

查看所有 CPU 使用情况

cpustat

或

mpstat -P ALL

每 1 秒刷新一次,共 5 次

mpstat 1 5

查看某个 CPU(如 CPU0)

mpstat -P 0 1 3

查看中断和上下文切换

mpstat -I ALL

二、Go 版 cpustat(perf-like)

如果你指的是 GitHub 上的 cpustat(by tools):

安装

sudo apt install golang-go
go install github.com/uber-common/cpustat@latest

使用

sudo $HOME/go/bin/cpustat

示例:

sudo cpustat -i 1

三、关键指标说明(mpstat 输出)

  • %usr:用户态 CPU
  • %sys:内核态 CPU
  • %iowait:IO 等待
  • %idle:空闲

四、常见问题

  • cpustat 命令不存在?
    → 实际用 mpstat
  • 数据全是 0?
    → 没启用 sysstat 服务

如果你能告诉我:

  • 是 哪种 cpustat
  • 想测 整机 / 单核 / 进程级

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

0 踩