Linux distributions provides a lot of tools in order to monitor system performance. vmstat
is one of the most used tool for system performance monitoring. vmstat
can collect and report information about memory, cpu, swap, io in a detailed way. In this tutorial we will examine the output of the vmstat
and different features and options of it.
List System Resource Usage
We will start by using vmstat
command without any option. This will list general statistics and information about system resource usage.
$ vmstat

We can see that there is 5 main column.
procs
display information about processes.memory
display information about memory metricsswpd
provides avaible swap sizefree
provides unused memory sizebuff
provides buffered memory sizecache
provides cached memory size
swap
provides swap related information but in these days it is not used so much.io
provides disk related informatinbi
block input shows data block count read from block devicesbo
block output shows block count sent to block devices
system
provides interrup and context switch information which is related with CPUin
number of interrupts per secondcs
number of context switches per second
cpu
provides CPU usage informationus
time spent user space operations or user timeid
time spent idlesy
time spent system operationswa
time spent waiting for IO.st
time spent from virtual machine
Print Output At Specified Interval Interactively
By default vmstat
command is non interactive. It will print information just one time after called and then quit. If we need to it continuously and print command output at given intervals we need to provide the interval as seconds after command. We will print at 5 second interval in this example.
$ vmstat 5

Print Timestamp
As the output printed one or multiple times we may need to know related time. We can print given information time by printing time stamp. We need to provide -t
option for this. Time column will be added as last column after cpu column.
$ vmstat -t

List Memory Active and Inactive
Active memory is part or size of the memory which is actively used currently running processes. Inactive memory is part or size of the memory where died or non existing processes. We will use -a
option for active and inactive memory. We can see that memory
column provides inact
and active
columns.
$ vmstat -a

View Disk I/O Statics In Detail
As writing disk and disk topology is a complex area related information can be printed with the -d
option. Following information will be provided by this option.
$ vmstat -d

Reads
show read related informationtotal
shows successfully completed total readmerged
shows grouped readssectors
shows sector readsms
shows milliseconds spent for reads
Writes
show write related informationtotal
shows successfully completed total readmerged
shows grouped readssectors
shows sector readsms
shows milliseconds spent for reads
IO
show currently active IO operations informationcur
I/O in progresss
seconds spent for I/O
View Disk I/O Statics Summary
We can also print disk related I/O statistics in summary or brief mode with -D
option.
$ vmstat -D

Usage Megabyte As Metric
During usage of all options the default metric for memory is byte. This will lower readability. We can make metrics more readable or human readable with -S M
option which will set Megabyte as metric.
$ vmstat -S M

List Event Counters and Memory Statics
We can use -s
option in order to print event counters and memory statistics.
$ vmstat -s
