在 Debian 系列系统中,cpustat 通常是指 cpustat 这个小工具(由 Colin Ian King 开发,用于按进程统计 CPU 使用情况)。下面说明安装和基本使用。
sudo apt update
sudo apt install cpustat
安装完成后检查:
cpustat --help
sudo apt install git build-essential
git clone https://github.com/ColinIanKing/cpustat.git
cd cpustat
make
sudo make install
sudo cpustat
默认每 1 秒采样一次,显示 CPU 使用最高的进程。
⚠️ 通常需要
sudo,否则无法读取所有进程信息
sudo cpustat 2 5
2:每 2 秒采样一次5:采样 5 次后退出sudo cpustat -c
sudo cpustat -p nginx
sudo cpustat -s
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-cache search cpustat
若无,使用源码方式安装。
cpustat:按进程级 CPU 统计,更直观mpstat:按CPU 核心级统计top:实时交互式如果你是想用 mpstat(sysstat 包) 或 sar,也可以告诉我,我可以分别说明。