在 Debian 上用 cpustat 监控 CPU,一般指的是 sysstat 包里的 mpstat / sar,或者 GitHub 上的 cpustat 工具。下面把两种常见用法都说明一下,你可以按需要选择。
sudo apt update
sudo apt install sysstat
sudo systemctl enable sysstat
sudo systemctl start sysstat
mpstat 是 sysstat 中用于 CPU 监控的工具,功能等同于“cpustat”。
mpstat -P ALL
mpstat -P ALL 2
mpstat -P ALL 2 5
输出示例:
CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle
all 12.3 0.0 4.1 1.2 0.0 0.1 0.0 0.0 0.0 82.3
sar -u 1 5
查看某天的历史(如 2026-01-20):
sar -u -f /var/log/sysstat/sa20
如果你指的是 cpustat 单文件工具(如 rumpelsepp/cpustat):
sudo apt install git make gcc
git clone https://github.com/rumpelsepp/cpustat.git
cd cpustat
make
sudo make install
cpustat
常见参数:
cpustat -i 1 # 每 1 秒刷新
cpustat -c 10 # 显示前 10 个进程
cpustat -n 20 # 显示 20 个采样
mpstat -P ALL 1
top
# 或
htop
mpstat -P ALL 1 60 > cpu.log
cpustat 命令mpstat / sar 即可| 需求 | 推荐 |
|---|---|
| 系统自带、稳定 | mpstat / sar |
| 实时、直观 | cpustat(GitHub) |
| 长期监控 | sar + cron |
| 服务器排查 | mpstat -P ALL |
如果你能贴一下 Debian 版本(cat /etc/os-release)以及你是想 实时监控 / 历史分析 / 脚本采集,我可以给你更精确的方案。