在 Debian 系统中,cpustat 通常是 sysstat 工具包的一部分,用于查看 CPU 使用率统计。下面从安装到常用用法给你一个完整说明。
sudo apt update
sudo apt install sysstat
安装完成后,cpustat 一般位于:
/usr/bin/cpustat
查看是否安装成功:
cpustat --help
cpustat
输出示例:
CPU user nice system idle iowait irq softirq steal guest
all 12.3 0.0 5.4 81.2 0.1 0.0 0.1 0.0 0.0
含义说明:
cpustat 1 5
含义:
cpustat -c
或:
mpstat -P ALL
(mpstat 也是 sysstat 里的工具,更常用)
cpustat -e
可显示 CPU 中断、上下文切换等扩展统计信息。
cpustat -p
watch -n 1 cpustat
cpustat -c 1 10
cpustat -e 1 5
| 工具 | 用途 |
|---|---|
| cpustat | 简洁 CPU 使用统计 |
| mpstat | 更详细,支持每个 CPU 核心 |
推荐:
mpstat -P ALL 1
sudo apt install sysstat
1 5 这种带间隔的方式sudo apt install sysstat
cpustat # 当前 CPU 使用
cpustat 1 5 # 每秒一次,共 5 次
cpustat -c # 每核 CPU
mpstat -P ALL # 推荐查看多核
如果你是想 排查 CPU 高负载 / 容器 / 虚拟化 / 服务器性能问题,可以告诉我具体场景,我可以给你更针对性的用法。