这个问题类似于如何记录 CPU 负载?,但我需要记录磁盘读/写速度负载。如果有办法同时记录 CPU 和磁盘负载就更好了,这样我就可以为给定的应用程序绘制一个图表,以显示该应用程序在给定时间间隔内 CPU 使用率和磁盘读/写速度的变化情况。需要说明的是,我所说的磁盘负载是指读取和写入速度,而不是磁盘容量的占用量。
答案1
您可以使用
我听从了 @waltinator 的建议,在存储库中搜索与性能相关的软件包。首先尝试了 iotop,但它需要超级用户权限。然后我尝试了 atop,对我来说效果很好,所以我记录了这个过程,以防其他人碰巧遇到与我相同的问题。
首先你需要安装 atop。你可以使用终端,输入以下命令:
sudo apt-get install atop
现在,只需在终端中输入命令,您就会看到大量有关系统的信息,如下面的屏幕所示。
相关部分是 CPU(大写表示总 CPU 统计信息)、cpu(小写表示每个核心)和 DSK(磁盘统计信息)前面的部分。要退出,只需输入 q。
例如,如果您只想查看全局 CPU 和磁盘信息,而不查看有关系统的所有额外信息,您可以在可解析输出模式(-P 标志)下运行 atop,以仅显示相关部分:
atop -P CPU,DSK
然后,每隔几秒(我认为默认是10秒),它就会输出相关的行,如下所示:
完成后,只需使用 Ctrl+c 返回终端。
您可以将可解析的输出从顶部重定向到 CSV 文本文件,以便您可以在电子表格中打开和编辑它,绘制您收集的数据的图表,例如:
atop -P CPU,DSK > stats_cpu_disk.csv
完成数据收集后,您可以按 Ctrl+c 停止,然后打开电子表格中生成的 csv 文件,使用空格作为列分隔符:
请注意,每个字段的标签未显示在可解析输出的顶部,但它们在手册中给出。下面我复制了相关部分:
PARSEABLE OUTPUT
With the flag -P followed by a list of one or more labels (comma-separated), parseable output is produced for each sample. The labels that can be
specified for system-level statistics correspond to the labels (first verb of each line) that can be found in the interactive output: "CPU", "cpu",
"CPL", "GPU", "MEM", "SWP", "PAG", "PSI", "LVM", "MDD", "DSK", "NFM", "NFC", "NFS", "NET" and "IFB".
For process-level statistics special labels are introduced: "PRG" (general), "PRC" (cpu), "PRE" (GPU), "PRM" (memory), "PRD" (disk, only if "storage
accounting" is active) and "PRN" (network, only if the kernel module 'netatop' has been installed).
With the label "ALL", all system and process level statistics are shown.
For every interval all requested lines are shown whereafter atop shows a line just containing the label "SEP" as a separator before the lines for the
next sample are generated.
When a sample contains the values since boot, atop shows a line just containing the label "RESET" before the lines for this sample are generated.
The first part of each output-line consists of the following six fields: label (the name of the label), host (the name of this machine), epoch (the
time of this interval as number of seconds since 1-1-1970), date (date of this interval in format YYYY/MM/DD), time (time of this interval in format
HH:MM:SS), and interval (number of seconds elapsed for this interval).
The subsequent fields of each output-line depend on the label:
CPU Subsequent fields: total number of clock-ticks per second for this machine, number of processors, consumption for all CPUs in system mode
(clock-ticks), consumption for all CPUs in user mode (clock-ticks), consumption for all CPUs in user mode for niced processes (clock-ticks),
consumption for all CPUs in idle mode (clock-ticks), consumption for all CPUs in wait mode (clock-ticks), consumption for all CPUs in irq
mode (clock-ticks), consumption for all CPUs in softirq mode (clock-ticks), consumption for all CPUs in steal mode (clock-ticks), consump‐
tion for all CPUs in guest mode (clock-ticks) overlapping user mode, frequency of all CPUs, frequency percentage of all CPUs, instructions
executed by all CPUs and cycles for all CPUs.
cpu Subsequent fields: total number of clock-ticks per second for this machine, processor-number, consumption for this CPU in system mode
(clock-ticks), consumption for this CPU in user mode (clock-ticks), consumption for this CPU in user mode for niced processes (clock-ticks),
consumption for this CPU in idle mode (clock-ticks), consumption for this CPU in wait mode (clock-ticks), consumption for this CPU in irq
mode (clock-ticks), consumption for this CPU in softirq mode (clock-ticks), consumption for this CPU in steal mode (clock-ticks), consump‐
tion for this CPU in guest mode (clock-ticks) overlapping user mode, frequency of this CPU, frequency percentage of this CPU, instructions
executed by this CPU and cycles for this CPU.
(...)
LVM/MDD/DSK
For every logical volume/multiple device/hard disk one line is shown.
Subsequent fields: name, number of milliseconds spent for I/O, number of reads issued, number of sectors transferred for reads, number of
writes issued, and number of sectors transferred for write.