- Linux vmstat 命令
- Q1。如何使用vmstat?
- Q2。如何使 vmstat 自动更新其输出?
- Q3。如何让vmstat显示slabinfo?
- Q4。如何让 vmstat 报告磁盘活动摘要统计信息?
- Q5。如何使 vmstat 将时间戳附加到每个输出行?
- 结论
如果您正在寻找可用于访问有关进程、CPU 活动、内存等信息的命令行实用程序,您会很高兴知道 vmstat 可以为您做这件事。
在本文中,我们将使用一些易于理解的示例来讨论该工具的基础知识。但在此之前,值得一提的是,本文中的所有示例都已在 Ubuntu 20.04 LTS 机器上进行了测试,但它也适用于 CentOS 和 Debian。
Linux 中的 vmstat 命令报告虚拟内存统计信息。以下是它的语法:
vmstat [options] [delay [count]]
以下是工具手册页对其的解释:
vmstat reports information about processes, memory, paging, block IO,
traps, disks and cpu activity.
The first report produced gives averages since the last reboot. Addi?
tional reports give information on a sampling period of length delay.
The process and memory reports are instantaneous in either case.
以下是一些 Q&A 风格的示例,可以让您更好地了解 vmstat 命令的工作原理:
对于基本用法,只需执行 vmstat sans 任何选项。
vmstat
例如,在我的例子中,上述命令产生了以下输出:
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
1 0 0 0 0 5 17 49 70 0 0 100 0 0
如第一行所示,输出分为六个部分。工具手册页包含有关这些值的详细信息。这是摘录:
Procs
r: The number of runnable processes (running or waiting for run time).
b: The number of processes in uninterruptible sleep.
Memory
swpd: the amount of virtual memory used.
free: the amount of idle memory.
buff: the amount of memory used as buffers.
cache: the amount of memory used as cache.
inact: the amount of inactive memory. (-a option)
active: the amount of active memory. (-a option)
Swap
si: Amount of memory swapped in from disk (/s).
so: Amount of memory swapped to disk (/s).
IO
bi: Blocks received from a block device (blocks/s).
bo: Blocks sent to a block device (blocks/s).
System
in: The number of interrupts per second, including the clock.
cs: The number of context switches per second.
CPU
These are percentages of total CPU time.
us: Time spent running non-kernel code. (user time, including nice time)
sy: Time spent running kernel code. (system time)
id: Time spent idle. Prior to Linux 2.5.41, this includes IO-wait time.
wa: Time spent waiting for IO. Prior to Linux 2.5.41, included in idle.
st: Time stolen from a virtual machine. Prior to Linux 2.6.11, unknown.
默认情况下,vmstat 产生一次输出。但是,如果您希望 vmstat 自动更新其输出,则可以通过指定一个数值作为命令的输入来实现。
此数值充当延迟(以秒为单位),之后更新输出。例如:
vmstat 3
这样,vmstat 输出将每 3 秒刷新一次。
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
1 0 0 0 0 5 17 49 70 0 0 100 0 0
0 0 0 0 0 0 181 108 143 0 0 100 0 0
0 0 0 0 0 0 7 92 132 0 0 100 0 0
0 0 0 0 0 0 0 87 124 0 0 100 0 0
...
...
...
对于 slabinfo,您需要使用 -m 命令行选项。请注意,您的 Linux 发行版内核需要支持 slabinfo 才能使用此选项。如果支持,则您需要使用 sudo 权限运行该命令。
sudo vmstat -m
例如,在我的例子中,这是生成的输出的摘录:
Cache Num Total Size Pages
ufs_inode_cache 0 0 808 40
qnx4_inode_cache 0 0 680 48
hfsplus_attr_cache 0 0 3840 8
hfsplus_icache 0 0 896 36
hfs_inode_cache 0 0 832 39
minix_inode_cache 0 0 672 48
ntfs_big_inode_cache 0 0 960 34
ntfs_inode_cache 0 0 296 55
jfs_ip 0 0 1280 25
xfs_dqtrx 0 0 528 31
xfs_dquot 0 0 496 33
xfs_buf 0 0 384 42
xfs_rui_item 0 0 696 47
xfs_rud_item 0 0 176 46
xfs_inode 0 0 1024 32
xfs_efd_item 0 0 440 37
xfs_buf_item 0 0 272 30
xfs_trans 0 0 232 35
xfs_da_state 0 0 480 34
xfs_btree_cur 0 0 224 36
...
...
...
为此使用 -D 命令行选项。
vmstat -D
这是此命令在我的系统上产生的输出:
10 disks
2 partitions
15066 total reads
5937 merged reads
read sectors
20063 milli reading
writes
merged writes
written sectors
milli writing
0 inprogress IO
126 milli spent IO
要确保 vmstat 命令将时间戳附加到每个输出行,请使用 -t 命令行:
vmstat -t
$ vmstat 2 -t
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu----- -----timestamp-----
r b swpd free buff cache si so bi bo in cs us sy id wa st UTC
2 0 0 0 0 5 17 49 70 0 0 100 0 0 2020-05-08 09:40:05
0 0 0 0 0 0 88 100 136 0 0 100 0 0 2020-05-08 09:40:07
0 0 0 0 0 0 18 90 139 0 0 100 0 0 2020-05-08 09:40:09
0 0 0 0 0 0 0 93 126 0 0 100 0 0 2020-05-08 09:40:11
0 0 0 0 0 0 10 107 144 0 0 100 0 0 2020-05-08 09:40:13
0 0 0 0 0 0 0 86 122 0 0 100 0 0 2020-05-08 09:40:15
0 0 0 0 0 0 0 101 135 0 0 100 0 0 2020-05-08 09:40:17
突出显示的条目显示每行中包含的时间戳。
根据您在 Linux 命令行上执行的工作类型,vmstat 命令可能会非常有用。除了此处讨论的选项外,此工具还提供了许多其他命令行选项。前往此处了解更多信息。
版权声明:
本文来源网络,所有图片文章版权属于原作者,如有侵权,联系删除。
本文网址:https://www.mushiming.com/mjsbk/14641.html