vmstat:一个标准的报告虚拟内存统计工具
![](http://static.careerengine.us/api/aov2/http%3A_%7C__%7C_mmbiz.qpic.cn_%7C_mmbiz_jpg_%7C_eQYGxygoIB91um7WnDmtJ0YzgicrcG1QdtDW4hgFQBqTnMlf1XVTTt7ibQMTOUtBRU8940J63EiczAwx8ahyiciaNiaQ_%7C_0%3Fwx_fmt%3Djpeg.jpg)
![](http://static.careerengine.us/api/aov2/http%3A_%7C__%7C_mmbiz.qpic.cn_%7C_mmbiz_jpg_%7C_eQYGxygoIB91um7WnDmtJ0YzgicrcG1QdtDW4hgFQBqTnMlf1XVTTt7ibQMTOUtBRU8940J63EiczAwx8ahyiciaNiaQ_%7C_0%3Fwx_fmt%3Djpeg.jpg)
编译自: http://www.2daygeek.com/linux-vmstat-command-examples-tool-report-virtual-memory-statistics/
作者: Magesh Maruthamuthu
译者: geekpi
什么是 RAM?
在智能手机世界,我们每一个人都知道 RAM。因此,我不想深入介绍,这样我就简要概括下。RAM 代表“随机访问内存”,是一种计算机数据存储,它会存储经常使用的程序来提升系统性能。
什么是虚拟内存?
虚拟内存是一种内存管理方式,计算机通过临时将最近未使用的程序数据从 RAM 转移到硬盘,以平衡或管理内存的短缺。
什么是 vmstat?
vmstat 是一个标准的工具,它会报告 Linux 系统的虚拟内存统计。vmstat 会报告有关进程、内存、分页、块 IO、陷阱(中断)和 cpu 活动的信息。它可以帮助 Linux 管理员在解决问题时识别系统瓶颈。
在 Linux 中安装 Sysstat
Linux 中没有独立的
vmstat
包。它与 sysstat
绑定在一起,并在大多数发行版的默认仓库上都有。如果还没有安装,只要基于你的发行版输入下面的命令。[在CentOS/RHEL 中安装vmstat]
$ sudoyum install sysstat
[在Fedora中安装vmstat]
$ sudo dnf install sysstat
[在Debian/Ubuntu中安装vmstat]
$ sudoapt-get install sysstat
[在ArchLinux中安装vmstat]
$ sudo pacman -S sysstat
[在Mageia中安装vmstat]
$ sudo urpmi sysstat
[在 openSUSE 中安装vmstat]
$ sudo zypper install sysstat
不带参数运行 vmstat
假设你已经成功安装 vmstat,在终端中不带参数运行
vmstat
,它会向你展示 vmstat 的默认结果。#vmstat
procs -----------memory-------------swap-------io-----system------cpu----
r b swpd free buff cache si so bi bo in cs us sy id wa
2079496161412013924078792800231000111880
当你看到上面的输出,你可能已经大致了解了它是什么以及它的目的。不要担心,我们将深入解释每个参数,以便你可以了解 vmstat 的用途和目的。
procs
:procs 中有 r
和 b
列,它报告进程统计信息。在上面的输出中,在运行队列(r
)中有两个进程在等待 CPU 并有零个休眠进程(b
)。通常,它不应该超过处理器(或核心)的数量,如果你发现异常,最好使用 top 命令[1]进一步地排除故障。r
:等待运行的进程数。b
:休眠状态下的进程数。
memory
: memory 下有报告内存统计的 swpd
、free
、buff
和 cache
列。你可以用 free -m
命令看到同样的信息。在上面的内存统计中,统计数据以千字节表示,这有点难以理解,最好添加 M
参数来看到以兆字节为单位的统计数据。swpd
:使用的虚拟内存量。free
:空闲内存量。buff
:用作缓冲区的内存量。cache
:用作高速缓存的内存量。inact
:非活动内存的数量。active
:活动内存量。
swap
:swap 有 si
和 so
列,用于报告交换内存统计信息。你可以用 free -m
命令看到相同的信息。si
:从磁盘交换的内存量(换入,从 swap 移到实际内存的内存)。so
:交换到磁盘的内存量(换出,从实际内存移动到 swap 的内存)。
I/O
:I/O 有 bi
和 bo
列,它以“块读取”和“块写入”的单位来报告每秒磁盘读取和写入的块的统计信息。如果你发现有巨大的 I/O 读写,最好使用 iotop[2] 和 iostat[3] 命令来查看。bi
:从块设备接收的块数。bo
:发送到块设备的块数。
system
:system 有 in
和 cs
列,它报告每秒的系统操作。in
:每秒的系统中断数,包括时钟中断。cs
:发送到块设备的块数。
CPU
:CPU 有 cs
、us
、sy
、id
和 wa
列,报告(所用的) CPU 资源占总 CPU 时间的百分比。如果你发现异常,最好使用 top
和 free
命令。cs
:每秒的系统中断数,包括时钟。us
:发送到块设备的块数。sy
:用作高速缓存的内存量。id
:非活动内存量。wa
:活动内存量。
以 MB 方式输出
默认情况下,vmstat 以千字节为单位显示内存统计,这是非常难以理解的,最好添加
-S m
参数以获取以兆字节为单位的统计。#vmstat-S m
procs -----------memory-------------swap-------io-----system------cpu----
r b swpd free buff cache si so bi bo in cs us sy id wa
10103371406211600401500111870
以延迟方式运行 vmstat 获取更好的统计信息
默认情况下,vmstat 的单次统计信息不足以进一步进行故障排除,因此,添加更新延迟(延迟是更新之间的延迟,以秒为单位)以定期捕获活动。如果你想以 2 秒延迟运行 vmstat ,只需使用下面的命令(如果你想要更长的延迟,你可以根据你的愿望改变)。
以下命令将每 2 秒运行一次,直到退出。
#vmstat2
procs -----------memory-------------swap-------io-----system------cpu----
r b swpd free buff cache si so bi bo in cs us sy id wa
10105500325776416016216691200401500111870
0010550032564441601621669200001310831174111870
0010550030864841602421669280011615591453162820
00105500285948416032216693200012934100391900
00105500326620416040216694000127922106891900
0010550036670441604821669440001783595591900
0010550036645641605621669480012285991891900
0010550036645641605621669480001515391504172810
001055003652244160602166996001199841097111880
带延迟和计数运行 vmstat
或者,你可以带延迟和特定计数运行 vmstat,一旦达到给定的计数,然后自动退出。
以下命令将每 2 秒运行一次,10 次后自动退出。
#vmstat210
procs -----------memory-------------swap-------io-----system------cpu----
r b swpd free buff cache si so bi bo in cs us sy id wa
1079496158191615738081041200231001111880
20794961559464157380810416001118211749212770
007949615837681573848104160014668179991900
20794961556364157384810428001113921545152830
00794961583272157384810428001013071448142840
207949615820321573848104280014142460541960
10794961575848157384810428001019122407262710
007949615828841573848104360016967882591900
2079496156936815739281043200112692096991900
107949615836121574008104440073920012530202770
显示活动和非活动内存
默认情况下,vmstat 会显示除活动和非活动内存之外的内存统计信息。如果要查看活动和非活动内存统计信息,请在 vmstat 后添加
-a
参数。#vmstat-a
procs -----------memory-------------swap-------io-----system------cpu----
r b swpd free inact active si so bi bo in cs us sy id wa
10105500238759241514858411200401501111870
打印磁盘统计
在 vmstat 后面添加
-d
参数会以每个磁盘一行的方式显示统计(包含读、写和 IO)。#vmstat-d
disk-------------reads------------------------writes----------------IO------
total merged sectors ms total merged sectors ms cur sec
ram0 0000000000
ram1 0000000000
ram2 0000000000
ram3 0000000000
ram4 0000000000
ram5 0000000000
ram6 0000000000
ram7 0000000000
ram8 0000000000
ram9 0000000000
ram10 0000000000
ram11 0000000000
ram12 0000000000
ram13 0000000000
ram14 0000000000
ram15 0000000000
loop0 0000000000
loop1 0000000000
loop2 0000000000
loop3 0000000000
loop4 0000000000
loop5 0000000000
loop6 0000000000
loop7 0000000000
fd0 0000000000
sda 1660405090449725948821905745573230037054280937702160032056118189160040915
sdb 25735757747998531247122045772353208502519128323736645890112509480182336
总结磁盘统计
在 vmstat 后面添加
-D
会显示全局统计(包括全部的磁盘、分区、全部读、合并的读、读取的扇区、写、合并的写、写入的扇区和 IO)。#vmstat-D
27 disks
3 partitions
275754028 total reads
1388030 merged reads
5751195976 read sectors
638710116 milli reading
38795040 writes
29520659 merged writes
2209820333 written sectors
130210652 milli writing
0 inprogress IO
224704 milli spent IO
打印指定分区统计
vmstat 添加
-p
参数后面跟上设备名会显示指定分区统计(包括读、读取的扇区、写以及请求的写)。#vmstat-p /dev/sdb1
sdb1 reads read sectors writes requested writes
311527890839453206728016
vmstat 统计信息带上时间戳
当你想在特定时间区间内找到内存尖峰时,用 vmstat 命令添加
-t
参数,后跟延迟和计数。注意:此组合不适用于基于 Debian 的系统。
#vmstat-t 15
procs -----------memory-------------swap-------io------system-------cpu---------timestamp---
r b swpd free buff cache si so bi bo in cs us sy id wa st
00069814161813242458860400010000100002017-01-1115:42:15 MST
2006981276181324245886040000914000100002017-01-1115:42:16 MST
00069820161813242458860400007511600100002017-01-1115:42:17 MST
0006982016181324245886040000433900100002017-01-1115:42:18 MST
000698228018132424588604000011318500100002017-01-1115:42:19 MST
打印更多统计
vmstat 后面跟上
-s
参数会显示不同统计的总结。#vmstat-s
32849392 total memory
25864128 used memory
16468180 active memory
8320888 inactive memory
6985264 free memory
181324 buffer memory
24588612 swap cache
20970492 total swap
0 used swap
20970492 free swap
891075 non-nice user cpu ticks
6532nice user cpu ticks
1507099 system cpu ticks
18925265601 idle cpu ticks
113043 IO-wait cpu ticks
108 IRQ cpu ticks
4185 softirq cpu ticks
0 stolen cpu ticks
4071862 pages paged in
216759718 pages paged out
0 pages swapped in
0 pages swapped out
369611221 interrupts
477861261 CPU context switches
1478258826 boot time
2196121 forks
打印 slab 统计
vmstat 后面跟上
-m
参数会显示 slab 信息。#vmstat-m
CacheNumTotalSizePages
nf_conntrack_expect 0024016
nf_conntrack_ffffffff81b2a920 186031212
fib6_nodes 24596459
ip6_dst_cache 163038410
ndisc_cache 73025615
ip6_mrt_cache 0012830
RAWv6353510887
UDPLITEv60010244
UDPv641210244
tw_sock_TCPv6 0032012
request_sock_TCPv6 0019220
TCPv64619202
fat_inode_cache 566726
fat_cache 0032112
ioat2 4096414012830
ext4_inode_cache 343223436410004
ext4_xattr 008844
.
.
.
阅读更多关于 vmstat
如果你想了解关于 vmstat 的更多选项,请阅读手册。
#vmstat--help
或者
#manvmstat
作者简介:
Magesh Maruthamuthu,热爱玩所有的 Linux 发行版
推荐文章
< 左右滑动查看相关文章 >
输入文章 ID 或长按二维码直达
[1]: http://www.2daygeek.com/top-command-examples-to-monitor-server-
[2]: http://www.2daygeek.com/monitor-disk-io-activity-using-iotop-
[3]: http://www.2daygeek.com/monitor-disk-io-activity-using-iotop-
[4]: http://www.2daygeek.com/author/magesh/
[5]: https://github.com/LCTT/TranslateProject
最新评论
推荐文章
作者最新文章
你可能感兴趣的文章
Copyright Disclaimer: The copyright of contents (including texts, images, videos and audios) posted above belong to the User who shared or the third-party website which the User shared from. If you found your copyright have been infringed, please send a DMCA takedown notice to [email protected]. For more detail of the source, please click on the button "Read Original Post" below. For other communications, please send to [email protected].
版权声明:以上内容为用户推荐收藏至CareerEngine平台,其内容(含文字、图片、视频、音频等)及知识版权均属用户或用户转发自的第三方网站,如涉嫌侵权,请通知[email protected]进行信息删除。如需查看信息来源,请点击“查看原文”。如需洽谈其它事宜,请联系[email protected]。
版权声明:以上内容为用户推荐收藏至CareerEngine平台,其内容(含文字、图片、视频、音频等)及知识版权均属用户或用户转发自的第三方网站,如涉嫌侵权,请通知[email protected]进行信息删除。如需查看信息来源,请点击“查看原文”。如需洽谈其它事宜,请联系[email protected]。