Sunday, October 19, 2014

vmstat in Linux - Monitoring resource usage in Linux

vmstat stands for Virtual Memory statistics. It's a utility which collects and displays parameters about processes, memory, paging, block IO, traps, disks and cpu activity. 

vmstat can be run by giving the time interval in which vmstat will collect and display the information. vmstat can be run with following command

vmstat <interval to summarize the data> <Total run>


For example, for data collection to be averaged on 1 sec and to get total 10 data points, run vmstat as 

vmstat 1 10

The output would look like (from my ubuntu 10.04 Linux)

procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa
 0  0      0 325448  66840 245240    0    0   735    70  213  523 18  6 63 13
 0  0      0 325440  66840 245264    0    0     0   172  149  374  2  1 97  0
 3  0      0 325440  66840 245264    0    0     0     0  118  291  0  0 100  0
 0  0      0 325440  66840 245264    0    0     0     0  111  262  0  1 99  0
 3  0      0 325440  66840 245264    0    0     0     0  116  271  0  0 100  0

Each line of data is averaged for 1 second interval.

Let's look into what the different data points mean. The major categories in which data points are reported are the major headings on the top. Let's go through them

procs - Processes waiting to run
  • r: Number of processes waiting to get the processor time.
  • b: Processes in sleep state. 
 memory - Tells about the details of memory
  • swpd: Virtual memory used
  • free: Free memory
  • buff: Memory used for buffer. This is the memory used for data I/O operation. It could be data waiting to be written to disk. 
  • cache: The amount of memory used as cache. The kernel uses cache to improve performance. For example kernel may cache a file from disk for faster access. This memory is used in an unobtrusive way and the memory is released if other processes need it.
swap - Tells about swap system. Operating system uses swap as extended memory but it exists on disk. The values here tells about the activity happening to move data from in and out of swap.
  • si: Memory swapped from disk to real memory.
  • so: Memory swapped to disk
io - io activity for the blocks of data read or written.
  • bi: Blocks read from a block device like disk
  • bo: Blocks written to disk.
system - Details about system interrupts and context switching
  • in: Number of interrupts per second
  • cs: The number of context switches per second. A context switch is done by operating system so that it can give time slices to each running program.
cpu - cpu details. Shown in  percentages of total CPU time. The total sum of four column for each row is 100%.
       us: Time spent in user processes
       sy: Time spent in system/kernel processes
       id:  Idle time when CPU is doing nothing
       wa: Time when CPU is waiting on IO

For more details on vmstat, you can looking into manual pages by running following command

man vmstat

There are many more switches and flags which can help further in looking into more details.

No comments:

Post a Comment