Linux real-time monitoring tool vmstat
The official definition of vmstat is vmstat-Report virtual memory statistics, which is the statistics of virtual memory.
First, tracing:
What is virtual memory?
A: The virtual memory is a virtual file on the disk that can be used as the memory.
Why is there virtual memory?
A: The program needs to run through the memory. If the program consumes too much memory during execution and the memory is exhausted, the program running will be affected. In this case, the virtual memory will come out-call the hard disk space to act as the memory, relieve the memory shortage, and make the program run smoothly. However, reading through the hard disk is far less efficient than reading directly from the memory (so if you have the conditions, buy more memory)
Enter the subject:
What are the metrics of vmstat?
A: process, memory, paging, block I/O, traps, and CPU Activity
Vmstat parameters?
-V prints version. displays the version number.
-N causes the headers not to be reprinted regularly. the field name is only displayed once.
-A print inactive/active page stats. Displays inactive/active memory
-D prints disk statistics: Displays disk data
-D prints disk table: displays the disk statistical table
-P prints disk partition statistics: Displays disk partition information
For example, [root @ localhost/] # vmstat-p/dev/sda2
Sda2 reads read sectors writes requested writes
41788 1781810 22914859 360923320
-S prints vm table displays memory-related statistics and various activities
-M prints slabinfo: displays slabinfo information. slab is a memory allocation mechanism in Linux.
-T add timestamp to output: display the time in the result
-S unit size specifies the memory display unit, in the unit of k, K, m, M (1000,102 4, 1000000, or 1048576 bytes)
Explanation of vmstat results:
[Root @ localhost/] # 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
Number of processes that procs r runs and waits for CPU
B. Number of processes waiting for resources
Memory swpd virtual memory usage
Free idle memory
Buff memory used by the buff
Memory Used by cache
Swap capacity of swap si to read virtual memory from disk
So the amount of swap data written to the disk from the virtual memory
Total data read by IO bi from Block devices, read disk kb/s
Total data written by bo from Block devices, written to disk kb/s
Number of system in interruptions per second
Cs context switching times per second
Cpu us sy id wa user consumption, system consumption, idle status, IO wait consumption Percentage
Cpu loss of st Virtual Machine
Important:
R should not exceed the total number of CPUs.
B. Pay attention to it when it is very high for a long time.
It is recommended that swpd not be greater than 0. If it is greater than 0, then let's look at si and so. If it is 0 or very low, it's okay.
When the si and so values are relatively high and constantly changing, it indicates that the memory is insufficient and the data in the memory is frequently exchanged to the swap partition, which usually has a great impact on the system performance.
Bi, high bo values indicate high io pressure
Extended knowledge:
1. Status of the process
A: A process is the basic unit for system resource allocation and scheduling. It can apply for and own system resources. It is a dynamic concept. Simply put, it can be understood that a program is executed as a process. The main states are: Ready-run-blocking.
Ready: resources are obtained, waiting for the CPU to be obtained; running is the execution status of the program after the CPU is obtained; blocking refers to the process waiting for a certain condition (such as I/O operations or process synchronization ), status where the execution cannot continue until the conditions are met
R and B in vmstat can understand their principles.
2 devices and character Devices
A: They are two types of I/o devices. Block devices store information in blocks of a fixed size. Each block has its own address. The size of a data block is usually between 512 bytes and 32768 bytes. The basic feature of Block devices is that each block can be read and written independently of other blocks. A disk is the most common block device. A character device is a device that transmits data in units of Characters During I/O transmission, such as a keyboard or printer.
3. Context switching
A: The CPU switches from one thread or process to another. To switch the CPU to another process, you need to save the status of the current process and restore the status of another process: the current running task changes to the ready (or suspended or deleted) state, and the other selected ready task becomes the current task. Context switching includes saving the running environment of the current task and restoring the running environment of the task to be run. If the number of threads that can be run is greater than the number of CPUs, the OS will forcibly suspend the threads that are being executed so that other threads can use the CPU, which will cause context switching, however, context switching will consume a lot of CPU time, So If context switching is frequent, you need to pay attention
Context switching may occur in three situations: Interrupt Processing, multi-task processing, and user mode switching.
4. Interruption
A: When necessary, the CPU temporarily stops executing the current program and then executes the program and execution process to handle new situations. Context switching is triggered when an interruption occurs.
Measure the test taker's knowledge about the metrics in vmstat by reading the source code.
Linux vmstat command details
Detailed description of vmstat display results in Linux
Vmstat for Linux monitoring tools
Linux vmstat commands
Linux vmstat monitors system load
Vmstat command details-Linux Performance Analysis
This article permanently updates the link address: