Linux performance monitoring command vmstat
Monitoring is usually divided into machine monitoring and service monitoring. Machine Monitoring is the basic monitoring to obtain the current running status of the system. service monitoring is the main purpose and the most important monitoring, machine Monitoring also exists for better service monitoring. In short, service monitoring is related to specific services deployed on the system, but the monitoring mode can be unified.
The purpose of monitoring is to obtain the relevant target data and analyze the data in case of exceptions. The purpose of analysis is to solve the problem of online case and performance tuning. This is basically the meaning of monitoring. Machine Monitoring of an online server can be divided into four categories: cpu monitoring, disk capacity monitoring, IO monitoring, and nic monitoring. Different services will lead to different server bottlenecks, depending on the specific business. This article mainly discusses the common command line for obtaining cpu status in Linux: vmstat.
Ii. Usage Details
Before using commands, you should understand the specific content and meaning of monitoring. Cpu monitoring is divided into two types: cpu usage and IPC/CPI. The application scenarios of the two are also different. Generally, cpu usage monitoring is used, which is basically provided by the operating system, however, IPC/CPI monitoring requires the assistance of performance experts, and there are basically no relevant commands in the operating system.
Non-computing-intensive instances only need to monitor cpu usage, while cpu usage needs to focus on user-mode cpu usage and system-mode cpu usage, the former indicates the percentage of cpu execution time obtained by running services on the system to the total cpu time, and the latter indicates the percentage of cpu time obtained by the system. For users, the user-mode cpu percentage of 100% is the most ideal situation, but this is generally impossible, when there is a program scheduling, thread context switching and IO interaction, the cpu usage in the system mode will increase significantly. It should be clear that the CPU consumption of applications does not mean that the performance or scalability has reached the maximum or bottleneck. If the system-state cpu usage remains high for a long time, you need to pay attention to it. It may be that the program write is not elegant, or the disk is about to be damaged, resulting in excessive IO consumption, at this time, cpu monitoring is required to analyze the results.
For Computing-intensive applications, it is not enough to only monitor cpu usage. You also need to monitor IPC (number of instructions per clock) or CPI (clock cycle per command ). Why do we need to know this data? Both IPC and CPI can reflect the percentage of cpu clock cycles used when no commands are executed. In short, they are the percentage of time consumed when the CPU waits for commands to be loaded into the registers from the memory, stall ). Stagnation-when the number of operations used by the cpu to execute commands is not in the register or cache, and the current clock cycle is not yet valid, the cpu needs to wait for the data to be loaded into the register from the memory. Once the stagnation occurs, it usually wastes several hundred cpu clock cycles. To improve the performance of computing-intensive applications, You need to obtain IPC/CPI monitoring data to reduce the downtime, reduce the cpu wait time for memory data, or improve the cache speed.
1. vmstat usage
[Work @ localhost ~] $ Vmstat -- help
Usage: vmstat [-V] [-n] [delay [count]
-V prints version.
-N causes the headers not to be reprinted regularly.
-A print inactive/active page stats.
-D prints disk statistics
-D prints disk table
-P prints disk partition statistics
-S prints vm table
-M prints slabinfo
-T add timestamp to output
-S unit size
Delay is the delay between updates in seconds.
Unit size k: 1000 K: 1024 m: 1000000 M: 1048576 (default is K)
Count is the number of updates.
2. vmstat example
[Work @ localhost ~] $ 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
0 0 0 56400 43444 324868 0 0 20 14 28 45 0 0 99 1 0
0 0 0 56400 43452 324864 0 0 0 48 36 58 0 0 98 2 0
0 0 0 56400 43452 324868 0 0 0 22 34 0 0 100 0
0 0 0 56400 43452 324868 0 0 0 34 48 0 1 99 0 0
1 0 0 56400 43452 324868 0 0 0 22 31 0 1 99 0 0
0 0 0 56400 43452 0 0 0 31 48 0 0 324868 0 0
0 0 0 56400 43452 324868 0 0 0 129 3 1 96 0
0 0 0 56400 43452 324868 0 0 0 35 56 0 2 98 0 0
0 0 0 56400 43452 0 0 0 22 32 0 0 324868 0 0
0 0 0 56400 43452 0 0 0 58 61 0 0 324868 0 0
0 0 0 56400 43452 324868 0 0 0 24 38 0 1 99 0 0
3. vmstat details
Vmstat 1: indicates that data is collected and displayed every second. To stop and press Ctrl + d, if you want to specify the number of times of collection, use "vmstat 1 10" to collect data every second, A total of 10 collection times.
R: indicates the number of processes that have been prepared except cpu resources, that is, the number of processes waiting for the available cpu. The value is obtained to determine the system load, if the value exceeds the number of hardware threads of the processor in a long time, you need to pay attention to the situation that the system may face high load. If the value is three or four times the number of hardware threads of the processor for a long time, you need to immediately pay attention to and take action. At this time, the system can feel a significant performance decline, either increase the cpu or analyze the current system process status.
Note: The concept of the number of hardware threads. For example, a dual-core cpu with four threads indicates that two physical CPUs exist, but each cpu has two logical threads. For the operating system, it thinks there are 4 CPUs.
B: indicates the blocked process queue. when the process is blocked, it is still in the memory (different from the suspended process, note the difference), but additional resources (such as IO) are required.
Us: indicates the user-mode cpu usage, that is, the percentage of cpu execution time occupied by the application. The proportion does not indicate the system bottleneck.
Sy: indicates the system-state cpu usage, which is usually the percentage of the total cpu usage by system scheduling.
Id: Percentage of idle time.
These three types of data are obtained to analyze and reduce the percentage of sy. In fact, to judge the cause of application exceptions, a lot of monitoring data needs to be integrated, depending on experience.
Si: the size of the virtual memory (swap) read from the disk per second. If this value is large, the system memory resources are insufficient and frequent memory exchanges are required.
So: The size of data written from memory to virtual memory per second, which is the same as that of si. However, when both values are large, the memory resources are insufficient.
Bi: The number of blocks received by Block devices (disks) per second. It corresponds to write operations in IO. Too large indicates frequent IO operations.
Bo: number of blocks output by the block device per second. This parameter corresponds to the read operation in IO, which is too large, indicating frequent IO operations.
In: The number of cpu interruptions per second.
Cs: the number of context switches per second. For example, calling system functions, thread context switches, and process switches will increase the value. context switches will waste the cpu clock and work with the in value, therefore, if the value is too long, you need to consider whether the number of threads in the application is too large.
If there are any mistakes or omissions in this article, please correct them. Thank you!
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: