Thursday, December 6, 2012

VMSTAT memory information

vmstat (virtual memory statistics) reports information about processes, memory, paging, block IO, traps, and cpu activity. Below is the sample default output generated by vmstat with no options:

bash> vmstat
procs -----------memory----------                 ---swap--      -----io----         -system--            -----cpu------
 r  b       swpd   free     buff         cache         si   so             bi    bo            in   cs             us sy id wa st
 2  1      0 200936584 2329428 53481392    0    0              60   113    0     0     2              1  9   7  0   0

Description of default output-

Procs           r: The number of processes waiting for run time.
                    b: The number of processes in un-interruptible sleep.

Memory     swpd: the amount of virtual memory used in KB.
                   free: the amount of idle memory in KB.
                   buff: the amount of memory used as buffers in KB.
                   cache: the amount of memory used as cache in KB.

Swap          si: Amount of memory swapped in from disk (KB/s).
                   so: Amount of memory swapped to disk (KB/s).

IO               bi: Blocks received from (read in) a block device (blocks/s).
                   bo: Blocks sent to (written out) 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           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.

Options associated with vmstat

       vmstat [-a] [-n] [delay [ count]]
       vmstat [-f] [-s] [-m]
       vmstat [-S unit]
       vmstat [-d]
       vmstat [-p disk partition]
       vmstat [-V]

-a  switch displays active/inactive memory, given a 2.5.41 kernel or better.

-f switch displays the number of forks since boot.  Each process is represented by one or more tasks,
               depending on thread usage.  This display does not repeat.

-m displays slabinfo.

-n switch causes the header to be displayed only once rather than periodically.

-s switch displays a table of various event counters and memory statistics. This display does
              not repeat.
delay is the delay between updates in seconds.  If no delay is specified, only one report is printed with
             the average values since boot.
count is the number of updates.  If no count is specified and delay is defined, count defaults to         
             infinity.

-d reports disk statistics (2.5.70 or above required)

-p followed by some partition name for detailed statistics (2.5.70 or above required)

-S followed by k or K or m or M switches outputs between 1000, 1024, 1000000, or 1048576 bytes
       The -V switch results in displaying version information.

Example -

Repeats 5 times interval 2 seconds

vmstat 2 5
procs -----------memory---------- ---swap-- -----io---- -system-- -----cpu------
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 2  0      0 200844476 2330340 53602492    0    0    60   112    0    0  2  1 97  0  0
 1  0      0 200853744 2330340 53602904    0    0    38   150 7055 10128  1  0 98  0  0
 2  0      0 200859260 2330340 53602900    0    0   103  3398 6828 9979  1  1 98  0  0
 1  0      0 200861660 2330340 53602904    0    0     5    58 6804 9784  1  0 99  0  0
 6  0      0 200824900 2330340 53602896    0    0    37    68 10740 11525  2  3 96  0  0

vmstat -a 2 4

procs -----------memory---------- ---swap-- -----io---- -system-- -----cpu------
 r  b   swpd   free  inact active   si   so    bi    bo   in   cs us sy id wa st
 3  0      0 200827012 4099080 46355812    0    0    60   112    0    0  2  1 97  0  0
 0  0      0 200836496 4099472 46353840    0    0    69   868 12479 12793  1  0 98  0  0
 1  0      0 200844692 4099864 46351732    0    0     5   232 12463 13112  1  1 98  0  0
 2  0      0 200831652 4099860 46370176    0    0   666  1275 13227 13570  2  1 97  0  0

 vmstat -f

    236676487 forks