Linux常用命令-vmstat

命令

vmstat

描述

Report virtual memory statistics
显示虚拟内存统计信息

用法

1
vmstat [options] [delay [count]]

选项

1
2
3
4
5
6
7
8
9
10
11
Options:
-a, --active 显示活动和非活动内存
-f, --forks 显示系统启动以来的fock数量
-n, --one-header 不重复显示标题
-s, --stats 显示事件计数器信息
-d, --disk 磁盘统计信息
-D, --disk-sum 磁盘信息汇总
-p, --partition <dev> 显示指定分区信息
-S, --unit <char> 指定显示单位,可选k, K, m, M,默认为K(1024 bytes)
-w, --wide 扩展显示宽度,自动对齐标题
-t, --timestamp 显示时间戳

注意

vmstat命令读取的是/proc/meminfo中的内存信息

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
$ free
total used free shared buff/cache available
Mem: 2027896 213880 1151712 9616 662304 1653784
Swap: 2097148 0 2097148
$ 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 1151648 2108 660176 0 0 13 33 61 75 1 0 99 0 0
# 间隔2s显示5次
$ vmstat 2 5
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 1230696 2108 648720 0 0 7 18 54 70 0 0 100 0 0
0 0 0 1230672 2108 648720 0 0 0 0 31 54 0 0 100 0 0
0 0 0 1230672 2108 648720 0 0 0 0 30 55 0 0 100 0 0
0 0 0 1230672 2108 648720 0 0 0 0 27 52 0 0 100 0 0
0 0 0 1230672 2108 648720 0 0 0 0 28 51 0 0 100 0 0
$ vmstat -a
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free inact active si so bi bo in cs us sy id wa st
1 0 0 1151672 188976 516364 0 0 13 33 61 75 1 0 99 0 0
$ vmstat -f
7090 forks
$ vmstat -s
2027896 K total memory
213872 K used memory
516628 K active memory
188912 K inactive memory
1151712 K free memory
2108 K buffer memory
660204 K swap cache
2097148 K total swap
0 K used swap
2097148 K free swap
13077 non-nice user cpu ticks
4 nice user cpu ticks
5651 system cpu ticks
2491988 idle cpu ticks
79 IO-wait cpu ticks
0 IRQ cpu ticks
322 softirq cpu ticks
0 stolen cpu ticks
329938 pages paged in
819778 pages paged out
0 pages swapped in
0 pages swapped out
1534516 interrupts
1869833 CPU context switches
1615525831 boot time
7192 forks
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 19G 0 part
├─centos-root 253:0 0 17G 0 lvm /
└─centos-swap 253:1 0 2G 0 lvm [SWAP]
$ vmstat -d
disk- ------------reads------------ ------------writes----------- -----IO------
total merged sectors ms total merged sectors ms cur sec
sda 6472 16 659877 3427 9583 617 1639660 12276 0 5
dm-0 5993 0 635702 3356 10190 0 1635524 13503 0 5
dm-1 88 0 4408 17 0 0 0 0 0 0
$ vmstat -D
3 disks
2 partitions
12553 total reads
16 merged reads
1299987 read sectors
6800 milli reading
19814 writes
618 merged writes
3275850 written sectors
25820 milli writing
0 inprogress IO
10 milli spent IO
$ vmstat -p /dev/sda1
sda1 reads read sectors writes requested writes
309 12439 10 4136
$ vmstat -p /dev/sda2
sda2 reads read sectors writes requested writes
6140 644766 9762 1639757
$ vmstat -S a
vmstat: -S requires k, K, m or M (default is KiB)
$ 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 st
1 0 0 1178 2 676 0 0 12 31 60 74 0 0 99 0 0
$ 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 st
1 0 0 1124 2 644 0 0 12 31 60 74 0 0 99 0 0
$ vmstat -w
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 1151144 2108 660404 0 0 12 31 60 74 0 0 99 0 0
$ vmstat -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 CST
1 0 0 1151268 2108 660404 0 0 12 31 60 74 0 0 99 0 0 2021-03-12 16:53:40
# 查看内存信息
$ more /proc/meminfo
MemTotal: 2027896 kB
MemFree: 1151480 kB
MemAvailable: 1653760 kB
Buffers: 2108 kB
Cached: 622632 kB
SwapCached: 0 kB
Active: 516468 kB
Inactive: 189064 kB
Active(anon): 81180 kB
Inactive(anon): 9228 kB
Active(file): 435288 kB
Inactive(file): 179836 kB
Unevictable: 0 kB
Mlocked: 0 kB
SwapTotal: 2097148 kB
SwapFree: 2097148 kB