cpustat 是一個用于監控系統 CPU 使用情況的工具,它是 sysstat 包的一部分。要在 Debian 系統上使用 cpustat 采集數據,請按照以下步驟操作:
sysstat 包。如果尚未安裝,請打開終端并運行以下命令:sudo apt-get update
sudo apt-get install sysstat
cpustat 工具將自動可用。要查看所有可用的 cpustat 選項,請在終端中運行以下命令:cpustat --help
cpustat 命令。例如,要查看 CPU 的實時使用情況,請運行:cpustat
這將顯示類似于以下的輸出:
Linux 5.4.0-42-generic (hostname) 05/01/2021 _x86_64_ (4 CPU)
avg-cpu: %user %nice %system %iowait %steal %idle
12.34 0.01 1.23 0.02 0.00 86.40
>)將輸出保存到文件。例如,要將數據保存到名為 cpu_usage.txt 的文件中,請運行:cpustat > cpu_usage.txt
watch 命令。例如,要每秒采集一次數據并將其追加到 cpu_usage.txt 文件中,請運行:watch -n 1 'cpustat >> cpu_usage.txt'
這將每秒更新一次 cpu_usage.txt 文件。
-s 選項指定間隔(以秒為單位)。例如,要每隔 5 秒采集一次數據并將其追加到 cpu_usage.txt 文件中,請運行:cpustat -s 5 >> cpu_usage.txt
這將在后臺運行 cpustat,每隔 5 秒將數據追加到 cpu_usage.txt 文件中。要停止采集數據,請按 Ctrl + C。
通過以上步驟,您可以在 Debian 系統上使用 cpustat 采集 CPU 數據。