Learn a Linux command every day (112): vmstat

Time:2021-9-14

Command introduction

The vmstat command is used for virtual memory statistics. Vmstat reports information about processes, memory, paging, block IO, traps, disks, and CPU activity.

Syntax format

vmstat [options] [delay [count]]

Option description

-A # show active inner page
-F # displays the total number of processes created since startup
-M # display slab information
-H # display help and exit
-N # header information is displayed only once
-S # displays event counters and memory status in tabular form
-D # report disk status
-P # displays the status of the specified hard disk partition
-S # output information unit
-V # displays version information and exits

Application examples

Show all information

[[email protected] ~]# vmstat
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 2  0      0 568632   2108 311348    0    0     7     1   50   38  2  1 98  0  0
#Refresh every 1 second
[[email protected] ~]# vmstat 1
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 2  0      0 568780   2108 311380    0    0     7     1   50   38  2  1 98  0  0
 0  0      0 568756   2108 311380    0    0     0     0   20   20  0  0 100  0  0
 0  0      0 568756   2108 311380    0    0     0     0   25   25  0  1 99  0  0
 0  0      0 568756   2108 311380    0    0     0     0   17   14  0  0 100  0  0
 0  0      0 568756   2108 311380    0    0     0     0   20   18  0  0 100  0  0
 0  0      0 568756   2108 311380    0    0     0     0   16   12  0  0 100  0  0
 0  0      0 568756   2108 311380    0    0     0     0   25   25  0  1 99  0  0

Field description of the result

#Procs (process)
r: Number of processes in the run queue
b: Number of processes waiting for IO

#Memory
Swpd: use virtual memory size
Free: free physical memory size
Buff: size of memory used as buffer
Cache: size of memory used as cache

#Swap
Si: the size written to memory from the swap area per second, which is transferred from disk to memory
So: the amount of memory written to the swap area per second, which is transferred from memory to disk
 
#IO (the block size of the current Linux version is 1KB)
Bi: number of blocks read per second
Bo: number of blocks written per second
 
#System
In: number of interrupts per second, including clock interrupts
CS: number of context switches per second
 
#CPU (in percentage)
 
Us: the percentage of execution time of the user process (user time). When the value of us is relatively high, it indicates that the user process consumes more CPU time.
SY: system time percentage of kernel system process execution time. When the value of SY is high, it indicates that the system kernel consumes more CPU resources.
Wa: percentage of IO waiting time. When the value of Wa is high, it indicates that IO waiting is serious.
 
#ID: idle time percentage

Displays the number of processes created since the system started

[[email protected] ~]# vmstat -f
         5303 forks

View disk status

[[email protected] ~]# vmstat -d
disk- ------------reads------------ ------------writes----------- -----IO------
       total merged sectors      ms  total merged sectors      ms    cur    sec
fd0        0      0       0       0      0      0       0       0      0      0
sda     8001     12  603239   68687   1841    278   64871  192251      0     91
sdb       92      0    5184     563      0      0       0       0      0      0
sr0       18      0    2056     245      0      0       0       0      0      0
dm-0    5949      0  579134   67305   2115      0   60775  227833      0     91
dm-1      88      0    4408     154      0      0       0       0      0      0

Displays the status of the specified disk partition

[[email protected] ~]# vmstat -p /dev/sda1
sda1          reads   read sectors  writes    requested writes
                1864      12369          4       4096
[[email protected] ~]# vmstat -p /dev/sda2
sda2          reads   read sectors  writes    requested writes
                6107     587782       1846      60879
[[email protected] ~]# vmstat -p /dev/sdb
partition was not found

So far, learning a Linux system command every day has pushed 112 articles. I hope it can help you. The system command is also the first step after the introduction of the system, and it is also a very important step. It is not easy to write articles by practicing more, operating more and summarizing more. If it is helpful, please praise, forward, share and support brother migrant worker.

Learn a Linux command every day (112): vmstat