[Linux] performance monitoring command vmstat and linux Command vmstat
I. Overview
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 --helpusage: 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 1procs -----------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 0 22 34 0 0 100 0 0 0 0 0 56400 43452 324868 0 0 0 0 34 48 0 1 99 0 0 1 0 0 56400 43452 324868 0 0 0 0 22 31 0 1 99 0 0 0 0 0 56400 43452 324868 0 0 0 0 31 48 0 0 100 0 0 0 0 0 56400 43452 324868 0 0 0 0 129 163 3 1 96 0 0 0 0 0 56400 43452 324868 0 0 0 0 35 56 0 2 98 0 0 0 0 0 56400 43452 324868 0 0 0 0 22 32 0 0 100 0 0 0 0 0 56400 43452 324868 0 0 0 0 58 61 0 0 100 0 0 0 0 0 56400 43452 324868 0 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.
Procs:
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.
Cpu:
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.
Swap:
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.
Io:
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.
System:
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.
More details: man vmstat (excerpt)
FIELD DESCRIPTION FOR VM MODE Procs r: The number of processes waiting for run time. b: The number of processes in uninterruptible sleep. Memory swpd: the amount of virtual memory used. free: the amount of idle memory. buff: the amount of memory used as buffers. cache: the amount of memory used as cache. inact: the amount of inactive memory. (-a option) active: the amount of active memory. (-a option) Swap si: Amount of memory swapped in from disk (/s). so: Amount of memory swapped to disk (/s). IO bi: Blocks received from a block device (blocks/s). bo: Blocks sent to a block device (blocks/s). System in: The number of interrupts per second, including the clock. cs: The number of context switches per second. CPU These are percentages of total CPU time. us: Time spent running non-kernel code. (user time, including nice time) sy: Time spent running kernel code. (system time) id: Time spent idle. Prior to Linux 2.5.41, this includes IO-wait time. wa: Time spent waiting for IO. Prior to Linux 2.5.41, included in idle. st: Time stolen from a virtual machine. Prior to Linux 2.6.11, unknown.FIELD DESCRIPTION FOR DISK MODE Reads total: Total reads completed successfully merged: grouped reads (resulting in one I/O) sectors: Sectors read successfully ms: milliseconds spent reading Writes total: Total writes completed successfully merged: grouped writes (resulting in one I/O) sectors: Sectors written successfully ms: milliseconds spent writing IO cur: I/O in progress s: seconds spent for I/O
Reference: Click to open the Link (http://www.cnblogs.com/yjf512/p/3383915.html)
Note:
If there are any mistakes or omissions in this article, please correct them. Thank you!