在 Debian 系统中,cpustat
是一个用于监控 CPU 性能和使用情况的工具,通常作为 sysstat
包的一部分提供。要查看 CPU 使用率图表,你可以按照以下步骤操作:
安装 sysstat 包(如果尚未安装):
sudo apt-get update
sudo apt-get install sysstat
使用 cpustat 查看 CPU 使用情况:
cpustat
会显示当前 CPU 的使用情况。你可以直接运行以下命令来查看:cpustat
Linux 5.4.0-42-generic (hostname) 09/16/2021 _x86_64_ (4 CPU)
09:12:34 PM CPU %usr %sys %iowait %irq %soft %steal %guest %idle
09:12:44 PM all 12.34 2.12 0.01 0.00 0.03 0.00 0.00 85.50
09:12:54 PM all 9.87 1.65 0.02 0.00 0.04 0.00 0.00 88.42
自定义输出:
-c
:显示每个 CPU 的详细信息。-m
:显示每个 CPU 的缓存使用情况。-P
:显示每个 CPU 的性能监控计数器。-t
:显示线程级别的统计信息。-h
:显示帮助信息。定时输出:
cpustat
命令与 watch
命令结合使用:watch -n 2 cpustat
将输出保存到文件:
cpustat
的输出保存到文件中,以便后续分析:cpustat -I 2 5 > cpu_usage.log
这将每隔 2 秒采样一次,共采样 5 次,并将结果保存到 cpu_usage.log
文件中。通过这些步骤,你应该能够在 Debian 上成功安装和使用 cpustat
来监控 CPU 的性能和使用情况,并生成相应的图表。