Quantcast
Channel: Linux by Examples » date
Viewing all articles
Browse latest Browse all 2

Obtain some system statistics from vmstat

$
0
0

vmstat know as virtual memory statistics reporter, but it gives more information the just only virtual memory.

Besides memory, it covers overall CPU usage, IO, Swap, Proc, System interupts and context switching. vmstat is pretty easy to use, ignores all other options, the normal usage will be looks like this:

vmstat [delay] [counts]

Let say, you want to print out the stat every 1 seconds for 60 times. Meaning you wanna to get the stat every second within a particular minute. You do this:

vmstat 1 60

The output will looks like this:

procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa
 3  0  57768   5712   4696 174692    0    0     0   496  458 1636 19  2 77  2
 2  0  57768   5712   4696 174692    0    0     0     0  466 1687 25  1 74  0
 0  0  57768   5712   4696 174704    0    0     0     0  438  990  7  1 92  0
 2  0  57768   5712   4696 174704    0    0     0     0  459 1020  6  0 94  0
 2  0  57768   5712   4696 174704    0    0     0     0  429  965  7  0 93  0
 2  0  57768   5712   4704 174696    0    0     0    40  455 1039  3  0 97  0
...

Okay, lets look at the field details:

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.

I usually interested on two field, under Memory, field free, that indicates me how much left my idle memory space. Under CPU, field id, it tells much how busy is my CPU is. If my free or id goes very low, that indicates my system is in a danger.

vmstat is very handy when comes to remote monitoring. You can ssh to a remote server execute vmstat for simple system monitoring like this:

ssh username@domain.com "vmstat 60 99999"

vmstat does not print out the date time, sometimes you wants to log down the stat with time stamp so that you can generate report based on the data you obtained.

Lets make use of some bash for loop, tail and date command,

vmstat 1 1;for ((;;));do date; vmstat 10 2 | tail -n1;done

The line above print out the stat every 10 seconds.

Output will looks like this:

procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa
 0  0  57644   6096   8080 160828    0    1    30    31  441  137 11  1 86  1
Sat Dec  8 12:51:40 MYT 2007
 0  0  57644   6152   8092 160828    0    0     0    38  449  989  8  0 92  0
Sat Dec  8 12:51:50 MYT 2007
 0  0  57644   5864   8108 160828    0    0     0     8  443  980  5  0 95  0
Sat Dec  8 12:52:00 MYT 2007
...

vmstat support display disk usage and other statistics as well, you can check out the man pages for more info.


Viewing all articles
Browse latest Browse all 2

Trending Articles