Monitoring and diagnostics

Command vmstat

Show memory statistics, CPU and IO

Linux · Bash examples · commands run on the selected server

When to use vmstat

Use vmstat to compare scheduling, memory and I/O activity across intervals. It is a system overview rather than a per-process profiler, so follow abnormal trends with tools that identify the responsible workload.

Syntax

vmstat [PARAMETERS] [INTERVAL [NUMBER]]

Square brackets mark optional arguments; an ellipsis means repetition. Replace example file names, user names and server addresses with your own values.

Common options and arguments

-w
Wide output format.
-s
Summary memory and event counters.
-d
Disk statistics.

Usage examples

Take five measurements

vmstat 1 5

Five reports are requested; the first usually contains averages since boot for rate fields.

View summary counters

vmstat -s

A summary of virtual-memory counters is displayed.

View wide output

vmstat -w 2 3

Wider interval reports make the columns easier to inspect.

Notes and limitations

  • The first report usually shows averages since boot; subsequent reports cover the selected interval.
  • Columns and units vary by version. Compare CPU usage, runnable tasks, swap and I/O.

Common questions and troubleshooting

Why is the first row unlike the later rows?

Many rate fields in the first report summarize time since boot; subsequent rows cover the requested interval.

Does swap usage mean the server is currently swapping heavily?

Not by itself. Existing swapped pages can remain when pressure subsides. Inspect swap-in and swap-out rates and application latency.

Further help

Options vary by version and distribution. Check the installed documentation with this command: man vmstat.