The Vmstat command is the most common Linux/unix monitoring tool that can show the status of a server at a given time interval, including server CPU utilization, memory usage, virtual memory exchange, IO Read and write situations.
The use of the general Vmstat tool is done by two numeric parameters, the first parameter is the number of time intervals sampled, the unit is seconds, the second parameter is the number of samples, such as:
# vmstat 2 1procs-------------memory--------------Swap-------io------System-------CPU-----r B swpd Free buff cache si so bi bo in CS US sy ID WA St 1 0 0 1023008 386244 90105984 0 0 0 0 0 0 The 0 0
2 indicates that the server state is collected every two seconds, and 1 means that it is collected only once.
In fact, in the application process, we will be monitoring for a period of time, do not want to monitor the direct end of Vmstat, such as:
# vmstat 2 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 0 1023008 386244 90105984 0 0 0 0 0 0 The 0 0 1 0 0 1023748 386244 90105984 0 0 5729 9138 0 0 0 0 1 0 0 1023784 386244 90106000 0 0 4529 7930 0 0 0 0 0 0 0 1024132 386244 90106008 0 0 4958 8171 0 0 0 0 0 0 0 1024780 386244 90106016 0 0 ( 5049 8616 0 0 0 0
This means that Vmstat collects data every 2 seconds and collects it until I have finished the program, and I have collected 5 data and I have finished the program.
Parameter description:
R means running the queue (that is, how many processes are really allocated to the CPU), the server I am testing is currently idle, there is no program running, when this value exceeds the number of CPUs, there will be a CPU bottleneck. This is also related to top of the load, the general load over 3 is relatively high, more than 5 is high, more than 10 is not normal, the state of the server is very dangerous. The load on top is similar to the run queue per second. If the running queue is too large, it means that your CPU is busy, which generally results in high CPU usage. When this value exceeds the number of CPUs, there is a CPU bottleneck. command to get the number of CPUs (Linux environment): Cat/proc/cpuinfo|grep processor|wc-l
b represents the blocking process, which is not much to say, the process is blocking
swpd Virtual memory has been used size, if greater than 0, indicates that your machine is out of physical memory, if not the cause of program memory leaks, then you should upgrade the memory or the memory-consuming task to other machines.
free physical memory size
Buff Linux/unix system is used to store, what content in the directory, permissions and other caches
The cache cache is used directly to memorize the files we open and to buffer the files.
Si reads the size of the virtual memory from the disk per second, if the value is greater than 0, the physical memory is not enough or the memory leaks, to find the consuming memory process to solve
so per second the virtual memory is written to the size of the disk, if this value is greater than 0, ibid.
Bi Blocks received from a block device (BLOCKS/S).-The number of blocks received per second from the block device, that is, the read block devices.
Bo Blocks sent to a block device (BLOCKS/S).-The number of blocks that are sent to the block device per second, that is, the write block devices.
in CPU interrupts per second, including time interrupts
CS per second, such as the number of context switches, such as we call the system function, the context switch, the thread of the switch, but also the process context switch, the smaller the value of the better, too big, to consider the number of threads or processes, such as in Apache and Nginx Web server , we generally do performance testing will carry out thousands of concurrent or even tens of thousands of concurrent testing, the process of selecting a Web server can be the peak of the process or the thread has been down, pressure measurement, until CS to a relatively small value, the process and the number of threads is a more appropriate value. System calls are also, each time the system function is called, our code will enter the kernel space, resulting in context switching, this is very resource-intensive, but also try to avoid frequent calls to system functions. Too many context switches means that most of your CPU is wasted in context switching, resulting in less time for the CPU to do serious work, and the CPU not being fully utilized, is undesirable.
US User CPU time
sy System CPU time, if too high, indicates a long system call time, for example, the IO operation is frequent.
ID Idle CPU time
wt wait IO CPU time
Identify CPU full load with Vmstat
The first thing to declare is that the CPU metric in Vmstat is a percentage. When the value of Us+sy is close to 100, it means that the CPU is nearing full-load operation. Note, however, that CPU-intensive work does not explain anything, and Unix always tries to make the CPU as busy as possible, maximizing the throughput of the task. The only value that can determine the CPU bottleneck is the R (running queue).
Linux-vmstat command Explanation