vmstat (virtual memory statistics) is a computer system monitoring tool that collects and displays summary information about operating system memory, processes, interrupts, paging and block I/O.
vmstat is a tool that collects and reports data about your system’s memory, swap, and processor resource utilization in real time. It can be used to determine the root cause of performance and issues related to memory use.
The vmstat tool is available on most Unix and Unix-like operating systems, such as FreeBSD, Linux or Solaris. The syntax and output of vmstat often differs slightly between different operating systems.
Options:-
-a The -a switch displays active/inactive memory, given a 2.5.41 kernel or better.
-f The -f switch displays the number of forks since boot. This includes the fork, vfork, and clone system calls,
and is equivalent to the total number of tasks created. Each process is represented by one or more tasks,
depending on thread usage. This display does not repeat.
-m The -m displays slabinfo.
-n The -n switch causes the header to be displayed only once rather than periodically.
-s The -s switch displays a table of various event counters and memory statistics. This display does not repeat.
delay delay is the delay between updates in seconds. If no delay is specified, only one report is printed with the
average values since boot.
count count is the number of updates. If no count is specified and delay is defined, count defaults to infinity.
-d The -d reports disk statistics (2.5.70 or above required).
-p The -p followed by some partition name for detailed statistics (2.5.70 or above required).
-s The -S followed by k or K or m or M switches outputs between 1000, 1024, 1000000, or 1048576 bytes.
-v The -V switch results in displaying version information.
FIELD DESCRIPTION FOR VM MODE:-
Proc:-
r: The number of processes 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, shown as zero.
FIELD DESCRIPTION FOR DISK MODE:-
Reads:-
total: Total reads completed successfully
merged: Grouped reads (resulting in one I/O)
sectors: Sectors read successfully
ms: Milliseconds spent reading
Writes:-
total: Total writes completed successfully
merged: Grouped writes (resulting in one I/O)
sectors: Sectors written successfully
ms: Milliseconds spent writing
IO:-
cur: I/O in progress
s: seconds spent for I/O
FIELD DESCRIPTION FOR DISK PARTITION MODE:-
reads: Total number of reads issued to this partition
read sectors: Total read sectors for partition
writes : Total number of writes issued to this partition
requested writes: Total number of write requests made for partition
FIELD DESCRIPTION FOR SLAB MODE:-
cache: Cache name
num: Number of currently active objects
total: Total number of available objects
size: Size of each object
pages: Number of pages with at least one active object
totpages: Total number of allocated pages
pslab: Number of pages per slab
FILES:-
/proc/meminfo
/proc/stat
/proc/*/stat
vmstat commands output with examples:-
1. To display active and inactive memory information status.
[root@liniuxbiginner ~]# 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
0 0 0 140268 48416 673184 0 0 0 103 5 2 0 0 99 1 0
2. To display no. of forks since last boot.
[root@liniuxbiginner ~]# vmstat -f
3357326 forks
3. To Display slab information.
[root@liniuxbiginner ~]# vmstat -m
Cache Num Total Size Pages
ip6-frags 0 0 232 35
UDPLITEv6 0 0 1088 30
UDPv6 30 30 1088 30
tw_sock_TCPv6 29 29 280 29
request_sock_TCPv6 0 0 328 24
TCPv6 15 15 2112 15
ext4_groupinfo_4k 336 336 144 28
ext4_inode_cache 76380 76516 1032 31
ext4_free_data 192 192 64 64
ext4_allocation_context 32 32 128 32
ext4_io_end 560 560 72 56
ext4_extent_status 30197 38454 40 102
jbd2_journal_handle 85 85 48 85
jbd2_journal_head 1088 1088 120 34
Timestamp:-
1. To display the timestamp along with every line.
[root@liniuxbiginner ~]# 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
0 0 0 139708 158452 193744 0 0 0 103 5 2 0 0 99 1 0 2016-06-28 11:15:17 UTC
2. To display every 3 seconds for 10 lines with timestamp.
[root@liniuxbiginner ~]# vmstat -t 3 10
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------ ---timestamp---
r b swpd free buff cache si so bi bo in cs us sy id wa st
0 0 0 139660 158472 193896 0 0 0 103 5 2 0 0 99 1 0 2016-06-28 11:22:28 UTC
0 0 0 139024 158472 193900 0 0 0 12 65 181 0 0 99 0 0 2016-06-28 11:22:31 UTC
0 0 0 139552 158472 193900 0 0 0 364 80 222 0 0 97 2 0 2016-06-28 11:22:34 UTC
0 0 0 139544 158472 193900 0 0 0 20 66 196 0 0 99 0 0 2016-06-28 11:22:37 UTC
0 0 0 139544 158472 193900 0 0 0 13 53 140 0 0 100 0 0 2016-06-28 11:22:40 UTC
0 0 0 139516 158472 193908 0 0 0 432 96 251 0 0 97 2 0 2016-06-28 11:22:43 UTC
0 0 0 138900 158472 193908 0 0 0 13 81 197 0 0 100 0 0 2016-06-28 11:22:46 UTC
0 0 0 139272 158472 193908 0 0 0 11 64 169 1 0 99 0 0 2016-06-28 11:22:49 UTC
0 0 0 139272 158472 193908 0 0 0 9 55 153 0 0 100 0 0 2016-06-28 11:22:52 UTC
0 0 0 139552 158472 193908 0 0 0 337 74 200 0 0 98 2 0 2016-06-28 11:22:55 UTC
3. To check vmstat version.
[root@liniuxbiginner ~]# vmstat -V
procps version 3.2.8
4. To display the event counter statistics in table format.
[root@liniuxbiginner ~]# vmstat -s
1019344 total memory
879884 used memory
673880 active memory
48312 inactive memory
139460 free memory
158496 buffer memory
194044 swap cache
0 total swap
0 used swap
0 free swap
1455666 non-nice user cpu ticks
267970 nice user cpu ticks
360814 system cpu ticks
522241945 idle cpu ticks
3575447 IO-wait cpu ticks
0 IRQ cpu ticks
17393 softirq cpu ticks
276374 stolen cpu ticks
1125512 pages paged in
542706588 pages paged out
0 pages swapped in
0 pages swapped out
329226970 interrupts
870644185 CPU context switches
1461822708 boot time
3358327 forks
To do not rediplay header:-
[root@liniuxbiginner ~]# vmstat -n
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
0 0 0 139484 158504 194092 0 0 0 103 5 2 0 0 99 1 0
1. To displays the read,I/O statistic and write of the disk statistics.
[root@liniuxbiginner ~]# vmstat -d
disk- ------------reads------------ ------------writes----------- -----IO------
total merged sectors ms total merged sectors ms cur sec
xvda 80091 47 2248744 665380 28417545 8633645 1085463440 150978028 0 37475
xvdb 286 0 2288 272 0 0 0 0 0 0
2. To display report summary statistics about disk activity.
[root@liniuxbiginner ~]# vmstat -D
2 disks
1 partitions
80378 total reads
47 merged reads
2251040 read sectors
665664 milli reading
28418044 writes
8633788 merged writes
1085482896 written sectors
150980548 milli writing
0 inprogress IO
37475 milli spent IO
3. To display reports with memory sizes reported in megabytes.you choose units (k, K, m, M) default is K (1024 bytes) in the default mode.
[root@liniuxbiginner ~]# vmstat -S m 3 1
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
0 0 0 142 162 198 0 0 0 103 5 2 0 0 99 1 0