温馨提示×

debian cpustat如何安装使用

小樊
42
2026-09-07 16:40:20
栏目: 智能运维

在 Debian 系列系统中,cpustat 通常是指 cpustat 这个小工具(由 Colin Ian King 开发,用于按进程统计 CPU 使用情况)。下面说明安装基本使用


一、安装 cpustat

方法 1:通过 apt 安装(推荐)

sudo apt update
sudo apt install cpustat

安装完成后检查:

cpustat --help

方法 2:从源码安装(apt 没有时)

sudo apt install git build-essential
git clone https://github.com/ColinIanKing/cpustat.git
cd cpustat
make
sudo make install

二、基本使用方法

1️⃣ 最简单用法

sudo cpustat

默认每 1 秒采样一次,显示 CPU 使用最高的进程。

⚠️ 通常需要 sudo,否则无法读取所有进程信息


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

sudo cpustat 2 5
  • 2:每 2 秒采样一次
  • 5:采样 5 次后退出

3️⃣ 显示所有 CPU 核心

sudo cpustat -c

4️⃣ 显示指定进程

sudo cpustat -p nginx

5️⃣ 按 CPU 使用率排序(默认行为)

sudo cpustat -s

6️⃣ 输出到文件(用于分析)

sudo cpustat 1 10 > cpu.log

三、输出字段说明(常见)

典型输出示例:

CPU  USR SYS IDLE  IO WAIT
 0   12  3   80    2    3

或进程级:

PID   %CPU  COMMAND
1234  25.3  python3

四、常见问题

❓ apt 找不到 cpustat?

先确认:

apt-cache search cpustat

若无,使用源码方式安装。

❓ 和 mpstat / top 的区别?

  • cpustat:按进程级 CPU 统计,更直观
  • mpstat:按CPU 核心级统计
  • top:实时交互式

如果你是想用 mpstat(sysstat 包)sar,也可以告诉我,我可以分别说明。

0