How to use vmstat command under Linux
vmstat is
virtual memory statistics
the abbreviation of. It is a very useful monitoring tool under Linux. In addition to memory, it also provides additional information such as block IO and CPU time.
grammar
The execution of the vmstat command does not require special permissions and can be executed by ordinary users. Its syntax is as follows
vmstat [options] [delay [count]]
delay
Indicates the data update interval, in seconds. If this value is not specified, it indicates the average time since the system started, and the result is only output once at this time.
count
Indicates the number of outputs. If this value is not specified, but the value of is specified
delay
, it means unlimited times.
Result field description
Enter on the command line
vmstat
and press Enter, the result will be output once
[root@cghost22 ~]# vmstat
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
3 0 0 991324 932 537336 0 0 0 0 3 4 0 0 100 0 0
[root@cghost22 ~]#
There are many fields in the results. The following table lists the detailed description of each field.
Field | illustrate |
---|---|
r | The number of runnable processes, including running and ready states |
b | Number of processes in uninterruptible sleep state |
swpd | Virtual memory usage |
free | free memory |
buff | The amount of memory used as buffer |
cache | The amount of memory used as cache |
and | Amount swapped into memory from disk |
so | Amount swapped out from memory to disk |
with a | Blocks received from the block device in blocks/second |
be | Blocks sent to block device, units: blocks/second |
in | Interrupts per second, including clock interrupts |
cs | Context switches per second |
us | User mode execution time |
and | Kernel mode execution time |
id | CPU idle time |
of | Waiting time for IO |
st | Time stolen from virtual machine |
In the second line of the table
处于不可中断睡眠状态的进程数量
, uninterruptible here refers to the state that a process enters when executing certain system calls. In this state, the process is blocked and cannot be interrupted until the system call is completed.
The field results are divided into several parts according to color, from top to bottom: process information, memory information, IO information, system interrupt and context, CPU time
The default unit of the value in the memory information is KB (1024 kbytes). The CPU time field does not represent a specific time, but a percentage of the total CPU time.
Common options
Options | illustrate |
---|---|
-a | Show active and inactive memory |
-f | The number of forks since system startup, including system calls such as fork, vfork and clone |
-s | Display system event counts and memory statistics |
-d | Report disk statistics |
-D | Statistical active disk information |
-p | Details of the specified partition |
-t | Add a column for time display |
-S | Display in specified byte units |
-In | Results are displayed in wide mode |
-IN | vmstat version |
Common usage
The vmstat command is mainly used to identify system bottlenecks. When counting statistics, it will not include its own process.
-
Output according to the specified time interval and number of times
[root@cghost22 ~]$ vmstat 2 10
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 12552 148356 234324 3382956 0 0 1 21 4 4 2 2 97 0 0
1 0 12552 148264 234324 3382980 0 0 0 0 14974 27478 3 2 96 0 0
1 0 12552 148232 234324 3382984 0 0 0 14 14384 27181 3 2 96 0 0
0 0 12552 148376 234332 3383052 0 0 0 204 14197 26812 4 2 94 0 0
0 0 12552 148512 234332 3383088 0 0 0 4 14398 27155 3 2 95 0 0
0 0 12552 147892 234332 3383128 0 0 0 210 15515 28802 3 2 95 0 0
1 0 12552 148388 234332 3383156 0 0 0 0 15147 28042 3 2 95 0 0
0 0 12552 148264 234332 3383168 0 0 0 4 14380 27395 3 1 96 0 0
0 0 12552 148264 234336 3383216 0 0 0 198 14430 27008 3 1 95 0 0
2 0 12552 148140 234336 3383252 0 0 0 6 14233 27161 3 2 95 0 0
2
Indicates that the result is output every 2 seconds,
10
indicating a total of 10 times of output, and the program automatically ends after 10 times.
-
Modify memory display unit
In the output results, the default unit of memory data is KB. You can
-S
adjust the displayed unit through the option. There are several units to choose from.
NOTE:
-S
Option
si、 so
is not valid for field
k # 1000 bytes
K # 1024 bytes
m # 1000 * 1000 bytes
M # 1024 * 1024 bytes
In the figure above, the memory data display unit in the first result is KB, and the unit in the second result is MB. Divide the value of the corresponding field of the first result by 1024 to get the second result.
-
Active memory and inactive memory
inact
Is inactive memory,
active
is active memory
Active memory is the memory used by processes, and inactive memory is the memory of processes that are not running.
-
Number of forks since system startup
The number of forks here includes system calls such as fork, vfork and clone.
[root@cghost22 ~]# vmstat -f
12714 forks
[root@cghost22 ~]# vmstat -f
12715 forks
[root@cghost22 ~]# vmstat -f
12716 forks
Every time we execute a command on the console, the system will fork a new process to execute the command. For example, in the above example, every time a
vmstat -f
command is executed, the system will fork a new process.
This option can also be used to count how many fork calls a certain operation consumes. You only need to execute
vmstat -f
the command once before and after the operation and compare the difference between the two results.
-
Append a column of time to each row
Adding a column of time display to help compare results over a period of time
-
Display in wide mode
The numbers in some fields in the vmstat results are sometimes relatively long, and are deviated from the position of the field names, which is not suitable for human viewing habits.
-w
The option can display the data in wide mode to make the results look more intuitive. The following pictures are respectively A comparison between not using wide mode and using wide mode
-
Statistics disk information
Disk information is mainly divided into three aspects: reading, writing, and IO. Reading and writing are measured in milliseconds, and IO is measured in seconds.
读
total: 成功读取的总数
merged: 分组读取(产生一个 IO)
sectors: 成功读取的扇区数
ms: 读取花费的毫秒
写
total: 成功写入的总数
merged: 分组写入(产生一个 IO)
sectors: 成功写入的扇区数
ms: 写花费的毫秒
IO
cur: 正在进行的IO
s: IO花费的秒数
-
Specify disk partition information
In the above figure, the output results show the information of the sda3 partition device, which includes: read count, number of read sectors, write count, and total number of partition write requests.
end
A mouthful of Linux
Follow and reply [ 1024 ] Massive Linux information will be given away
Collection of wonderful articles
Article recommendation
Click " Read the original text " to view more sharing, welcome to share, collect, like, and watch