introduction
vmstat obtains rough information about the performance of the whole system, including:
- Number of running processes
- CPU usage
- Number of interrupts received by CPU
- Number of context switches performed by the scheduler
grammar
NAME vmstat - Report virtual memory statistics Overview vmstat [-n] [delay[count]] vmstat [-V] describe vmstat Process, memory usage, swap pages and I/O Block usage, interrupts, and CPU Make statistics on the usage and report the corresponding information. The first display indicates the average usage of the computer since the last restart. Each subsequent line of information displays the information of each part of the system regularly according to the delay. Process information and memory information are generated immediately. option -n The switch causes the first information to be displayed only once instead of being generated periodically. deley Is the refresh interval in seconds. If this delay time is not given, only the average value since system startup is displayed. count Refers to the number of updates. If this number is not specified and a delay time is defined, the default value for the number of times is infinite. -V Switch can be used to output the version information of the command. Introduction to output information Procs r: Number of processes waiting to run b: The number of processes in non disruptive sleep w: The number of runnable processes swapped out. This number is determined by linux Calculated, but linux Does not exhaust the swap space Memory swpd: Virtual memory usage, unit: KB free: Free memory, unit KB buff: Memory used as cache, unit: KB Swap si: Number of swap pages swapped from disk to memory, unit: KB/second so: Number of swap pages swapped from memory to disk, unit: KB/second IO bi: The number of blocks sent to the block device, in blocks/second bo: The number of blocks received from the block device, in blocks/second System in: Number of interrupts per second, including clock interrupts cs: Number of environment (context) switches per second CPU Press CPU The total usage percentage of is displayed us: CPU Usage time sy: CPU System usage time id: Idle time be careful function vmstat No special permission is required These system information is used to provide users with information to analyze system bottleneck problems. linux Running will not be when calculating process conditions vmstat Count it yourself. Current linux All blocks are 1 in size K,and CD-ROM The block size of the file system is 2 K. Related documents /proc/meninfo /proc/stat /proc/*/stat reference resources ps(1),top(1),free(1)
vmstat runs in two modes: sampling mode and average mode.
- If no parameter is specified, vmstat statistics runs in the average mode, and vmstat displays the average value of all statistics since system startup
- If the delay is specified, the first sample is still the average since the system was started, but then vmstat will take statistics according to the delay seconds and display the statistics
Use example
(1) Query the average value of all statistical data since system startup
If vmstat does not use command-line parameters when running, it displays the average of the statistics recorded since the system was enabled.
$ 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 6152 458244 0 3936040 0 0 15 18 5 68 1 1 97 0 0
- The r column under "procs" is 1, and the number of running processes is 1
- From column b under "procs" as 0, you can know that there is no blocking process at run time
- As can be seen from us sy id wa under "CPU utilization", from system startup, the CPU has 1%(us) of time for executing user application code, 1% of time for executing system code, and 97% of time is idle. In other words, the system is basically idle from startup.
(2) Sampling
$ vmstat 2 5 #Sample once every 2 seconds for 5 times 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 6152 386456 0 3936372 0 0 15 18 10 73 1 1 97 0 0 1 0 6152 387860 0 3936372 0 0 0 0 2333 3590 1 5 93 0 0 1 0 6152 386400 0 3936372 0 0 0 10 2472 3774 2 5 93 0 0 1 0 6152 387952 0 3936388 0 0 0 0 3876 5420 2 7 91 0 0 2 0 6152 388344 0 3936388 0 0 0 10 2501 3738 1 5 93 0 0
The first line of output is the mean value since the system is started, followed by periodic sampling
(3) View CPU statistics
$ vmstat -s 7990288 K total memory 3663568 K used memory 3854300 K active memory 2807488 K inactive memory 389968 K free memory 0 K buffer memory 3936752 K swap cache 6291452 K total swap 6152 K used swap 6285300 K free swap 515755 non-nice user cpu ticks //------------------- 2350 nice user cpu ticks //------------ 537137 system cpu ticks //------------ 39704769 idle cpu ticks //------------ 5504 IO-wait cpu ticks //------------ 0 IRQ cpu ticks //------------ 10621 softirq cpu ticks //------------ 0 stolen cpu ticks //------------ 5921240 pages paged in 7180110 pages paged out 843 pages swapped in 2033 pages swapped out 91361854 interrupts //--------------- 160903598 CPU context switches 1638408247 boot time 861087 forks
Let's analyze the output information about CPU shown above
- cpu ticks indicates the CPU time since the system was started, and ticks is a time unit
- The above shows the distribution of all CPU ticks, such as system CPU, idle CPU, IO waiting CPU, soft interrupt CPU, etc
- A total of 91361854 interrupts have occurred since the system was started
- A total of 160903598 CPU context switches have occurred since the system was started
- Since system startup, 861087 new processes have been created
(4) vmstat can also record the behavior of the system under certain load or test conditions, so as to see how the system responds to parent-child and various system events
- Start vmstat before the test starts and stop vmstat after the test ends
- Vmstat is used to display the behavior of the system, and only the parameter delay is passed, vmstat will be adopted indefinitely, and tee command is used to output the results to a file
$ vmstat 1 | tee text.out procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu----- r b swpd free buff cache si so bi bo in cs us sy id wa st 2 1 6152 447288 0 3936728 0 0 14 18 18 85 1 1 97 0 0 0 0 6152 447276 0 3936728 0 0 20 0 2836 3878 1 5 93 1 0 1 0 6152 447056 0 3936752 0 0 0 20 2591 3762 2 5 93 0 0 1 0 6152 446668 0 3936752 0 0 0 8 2642 3875 1 6 94 0 0 1 0 6152 447164 0 3936752 0 0 0 0 2470 3764 1 5 93 0 0 ^C