cpustat 是 Debian/Ubuntu 等系统中一个轻量级、面向性能分析的 CPU 统计工具(通常来自 cpustat 软件包,由 Colin Ian King 开发)。它并不是系统默认必装工具,而是在特定分析和排障场景下非常适用。
下面从「什么时候该用 cpustat」的角度说明。
cpustat 能按 用户态 / 内核态 / 空闲 / IO等待 / 中断 等维度统计 CPU 使用。
适合:
cpustat 1
cpustat 可以显示每个进程的 CPU 占用百分比,比 top 更简洁、采样更稳。
适合:
cpustat -p 1
top 是交互式,cpustat 更适合:
适合:
cpustat -n 10 1 > cpu.log
cpustat 明确区分:
%usr%sys%irq%idle适合:
相比 htop、gnome-system-monitor:
❌ 需要长期历史数据 → 用 sar / prometheus
❌ 需要内存 / 磁盘 / 网络综合监控 → 用 atop
❌ 需要交互式操作 / 杀进程 → 用 htop
❌ 需要线程级分析 → 用 perf
| 目的 | 推荐工具 |
|---|---|
| 实时看 CPU 分布 | cpustat |
| 看进程树 | htop |
| 历史统计 | sar |
| 深度性能分析 | perf |
| 全资源快照 | atop |
sudo apt update
sudo apt install cpustat
当你需要在 Debian 上“轻量、清晰、周期性”地看 CPU 使用情况和进程占用时,
cpustat非常适用。
如果你有具体使用场景(比如容器、数据库、压测),我可以给你更针对性的用法。