The command vmstat reports information about processes, memory, paging, block IO, traps, and cpu activity. However, a real advantage of vmstat command output - is to the point and (concise) easy to read/understand. The output of vmstat command use to help identify system bottlenecks. Please note that Linux vmstat does not count itself as a running process.
vmstat <interval> <count>
<interval> is the interval in seconds between two runs. <count> is the number of repetitions vmstat makes. Here is a sample when we want vmstat to run every five seconds and stop after the tenth run. Every line in the output comes after five seconds and shows the stats at that time:
vmstat 5 10
The procs column consist of two sub-columns, 'r' and 'b'. The 'r' column show the number of processes waiting to be run. The more the load on the system, the more the number of processes waiting to get CPU cycles to run. The 'b' column show the number of uninterruptible sleeping processes, also known as “blocked” processes. These processes are most likely waiting for I/O but could be for something else too. Sometimes there is another column as well, under heading “w”, which shows the number of processes that can be run but have been swapped out to the swap area.
The numbers under “b” should be close to 0.
If the number under “w” is high, you may need more memory.
The sub-columns under the "memory" column is self-explainatory.
The next block shows swap activity. The 'si' column the rate at which the memory is swapped back from the disk to the physical RAM (in KB/sec). The 'so' column show the rate at which the memory is swapped out to the disk from physical RAM (in KB/sec).
The next block slows I/O activity. The 'bi' column shows the rate at which the system sends data to the block devices (in blocks/sec). The 'bo' column shows the rate at which the system reads the data from block devices (in blocks/sec).
The next block shows system related activities. The 'in' column show the number of interrupts received by the system per second. The 'cs' column show the rate of context switching in the process space (in number/sec)
The sub-columns under 'cpu' is self-explainatory. They are user, system, idle, and wait.
The first line of the output is an average of all the metrics since the system was restarted. So, ignore that line since it does not show the current status. The other lines show the metrics in real time.
Ideally, the number of processes waiting or blocking (under the “procs” heading) should be 0 or close to 0. If they are high, then the system either does not have enough resources like CPU, memory, or I/O.
The top command shows a CPU free% number. The difference is: top shows that free% for each CPU whereas vmstat shows the consolidated view for all CPUs.
If system CPU load is high, could there be some root process such as backup running?
vmstat -S M
-S M: vmstat lets you choose units (k, K, m, M) default is K (1024 bytes) in the default mode. I am using M since this system has over 4 GB memory. Without -M option it will use K as unit
To collect data every 2 seconds:
vmstat -S M 2
To collect data every 2 second 5 times only:
vmstat -S M 2 5