Linux Machine performance Monitoring with VMSTAT command

what is vmstat ?

vmstat is a tool that reports data about your machine’s processor,free memory,swap,io and cpu resource utilisation in real time. To check Linux machine performance monitoring with vmstat command is very easy. we can check and capture real time stats.

Fields description for VM mode:

Process:

  • r: The processes running or waiting.
  • b: The no.of busy processes.

Memory:

  • swapd: The amount of Virtual memory used.
  • free: free virtual memory.
  • buff:Memory used as buffers.
  • cache:The amount of memory used as cache.

Swap Segment:

  • si: Amount of memory swapped in from disk per every second.
  • so: Amount of memory swapped to disk per every second.

IO:

  • bi:  Blocks received from a block device per second.
  • bo: Blocks sent to a block device for second

System:

  • in: Interrupts per second, including the clock.
  • cs: Context switches per second.

CPU:

  • us: user time,including time
  • sy: system time
  • id: Time spent idle.
  • wa: included in idle.
  • st: Time stolen from a virtual machine.unknown.

Are You Ready For VMSTAT Command?

vmstat commands output with examples:

To display active and inactive memory information status

[root@server ~]# vmstat -a
 procs -----------memory---------- ----swap--- -----io---- --system-- ------cpu-----
 r b swpd free inact active si so bi bo in cs us sy id wa st
 1 0 0 560284 373736 686156 0 0 56 9 57 88 1 1 98 1 0

To display no. of forks since last boot

[root@server ~]# vmstat -f
 7420 forks

To Display slab information

[root@server ~]# vmstat -m
 Cache Num Total Size Pages
 isofs_inode_cache 102 102 640 51
 fuse_inode 42 42 768 42
 lio_cmd_cache 0 0 1216 26
 t10_alua_lu_gp_cache 48 48 168 48
 t10_pr_reg_cache 0 0 704 46

Timestamp :

To display the timestamp along with every line.

[root@server ~]# vmstat -t
 procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu------- -----timestamp-----
 r b swpd free buff cache si so bi bo in cs us sy id wa st IST
 1 0 0 560104 928 666184 0 0 51 9 54 85 1 1 98 1 0 2016-06-25 12:48:53

To display every 3 seconds for 10 lines with timestamp

[root@server ~]# vmstat -t 3 10
 procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu----- -----timestamp-----
 r b swpd free buff cache si so bi bo in cs us sy id wa st IST
 1 0 0 560336 928 666168 0 0 50 8 54 85 1 1 98 1 0 2016-06-25 12:49:49
 0 0 0 560336 928 666168 0 0 0 0 58 104 0 0 100 0 0 2016-06-25 12:49:52
 0 0 0 560336 928 666168 0 0 0 0 62 113 0 0 100 0 0 2016-06-25 12:49:55
 0 0 0 560336 928 666168 0 0 0 0 50 92 0 0 100 0 0 2016-06-25 12:49:58

To check vmstat version

[root@server ~]# vmstat -V
 vmstat from procps-ng 3.3.10

To display the event counter statistics in table format

[root@server ~]# vmstat -s
 1870512 K total memory
 643092 K used memory
 686092 K active memory
 373736 K inactive memory
 560304 K free memory
 928 K buffer memory
 666188 K swap cache
 2097148 K total swap
 0 K used swap
 2097148 K free swap
 6587 non-nice user cpu ticks
 330 nice user cpu ticks
 5307 system cpu ticks
 1059668 idle cpu ticks
 5873 IO-wait cpu ticks
 0 IRQ cpu ticks
 499 softirq cpu ticks
 0 stolen cpu ticks
 516230 pages paged in
 87609 pages paged out
 0 pages swapped in
 0 pages swapped out
 573973 interrupts
 904539 CPU context switches
 1466834010 boot time
 7549 forks

To do not rediplay header:-

[root@server ~]# vmstat -n
 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 560328 928 666188 0 0 47 8 53 83 1 1 98 1 0

To displays the read,I/O statistic and write of the disk statistics.

[root@server ~]# vmstat -d
 disk- ------------reads------------ ------------writes----------- -----IO------
 total merged sectors ms total merged sectors ms cur sec
 sda 12574 826 1029293 269025 4627 397 175339 71718 0 102
 sdb 377 1 3024 361 0 0 0 0 0 0
 sr0 25 0 144 483 0 0 0 0 0 0
 dm-0 252 0 2016 2141 0 0 0 0 0 1
 dm-1 12584 0 970253 273490 4759 0 171217 93597 0 100
 dm-2 91 0 728 29 0 0 0 0 0 0

To display report summary statistics about disk activity

[root@server ~]# vmstat -D
 6 disks
 3 partitions
 25903 total reads
 827 merged reads
 2005458 read sectors
 545529 milli reading
 9452 writes
 403 merged writes
 347146 written sectors
 165368 milli writing
 0 inprogress IO
 203 milli spent IO

To display specific partition statistics

[root@server ~]# vmstat -p /dev/sda1 1 3
 sda1 reads read sectors writes requested writes
 338 54744 265 4122
 338 54744 265 4122
 338 54744 265 4122

To display reports with memory sizes reported in megabytes.you choose units (k, K, m, M) default is K (1024 bytes) in the default mode

[root@server ~]# vmstat -S m 3 1
 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 571 0 682 0 0 33 6 46 76 0 0 99 0 0

Files

/proc/meminfo
/proc/stat
/proc/*/stat

Conclusion

vmstat command is used to collect stats about CPU, Free memory, IO and swap.

Please Provide your Valuable feedback.  Thank You!

Other resources to know more about vmstat command

Related Posts

25 most commonly used commands

cd command in centos

Thanks for your wonderful Support and Encouragement