在 Debian 里 cpustat 通常指两种东西之一,需要先区分一下:
mpstat / sar(很多人误叫 cpustat)cpustat)下面分别说明 真正叫 cpustat 的工具在 Debian 上怎么安装和配置。
sudo apt update
sudo apt install cpustat
安装完成后可直接运行:
sudo cpustat
cpustat 是实时采样工具,一般不需要复杂配置文件。
sudo cpustat 1 5
sudo cpustat -c
sudo cpustat -p
sudo cpustat 1 10 > cpu.log
| 参数 | 作用 |
|---|---|
-c |
显示每个 CPU |
-p |
显示进程 |
-t |
显示时间戳 |
-n N |
只显示前 N 个进程 |
-s |
显示系统汇总 |
-h |
帮助 |
示例:
sudo cpustat -c -p -t 2 5
cpustat 本身 没有配置文件,但你可以:
sudo systemctl edit --full cpustat.service
示例 service(不常用,仅举例):
[Unit]
Description=cpustat monitor
[Service]
ExecStart=/usr/bin/cpustat 5 1000 >> /var/log/cpustat.log
sudo crontab -e
*/5 * * * * /usr/bin/cpustat 1 1 >> /var/log/cpustat.log
如果你是想做历史 CPU 统计:
sudo apt install sysstat
sudo systemctl enable --now sysstat
查看:
sar -u 1 3
cpustat 是 实时诊断工具cpustat [间隔] [次数] [选项]如果你能告诉我:
我可以给你更精确的用法示例。