vmstat - Linux


Overview

The vmstat command in Linux reports information about processes, memory, paging, block IO, traps, disks, and CPU activity. It is mainly used for monitoring system performance and identifying system bottlenecks. This command is essential for system administrators and performance analysts when diagnosing system health and performance issues.

Syntax

The basic syntax of vmstat is:

vmstat [options] [delay [count]]
  • delay – The time interval in seconds between each report.
  • count – The number of updates. If omitted, reports are generated until the process is manually stopped.

Options/Flags

  • -a: Includes active/inactive memory information.
  • -d: Reports disk statistics.
  • -D: Displays disk table.
  • -n: With a specified delay, it causes the headers not to be repeated.
  • -p <disk partition>: Provides statistics for a partition.
  • -s: Outputs memory statistics.
  • -S <unit>: Defines the units used for reporting (k for kilobytes, m for megabytes).
  • -t: Adds a timestamp to each report.
  • -m: Displays slabinfo.
  • -w: Display wide output.
  • -V: Shows the version of vmstat.

Options can be combined to tailor the output as per requirements.

Examples

  1. Basic Usage:

    vmstat
    

    This command displays a summary of key system statistics.

  2. Specifying Interval and Count:

    vmstat 5 10
    

    Reports every 5 seconds, 10 times.

  3. Monitoring Disks:

    vmstat -d
    

    Displays detailed disk statistics.

  4. Timestamped Reports:

    vmstat 3 -t
    

    Displays reports every 3 seconds with a timestamp.

  5. Using Wide Output:

    vmstat -w
    

    Offers a wider view which can be useful on larger screens.

Common Issues

  • Performance Impact: Frequent use of vmstat with short delay times can itself impact system performance.
  • Misinterpretation of Output: Without understanding what each column represents, it’s easy to misinterpret the output. Consult the vmstat man page for detailed column descriptions.

Integration

vmstat can be combined with other tools like grep for more refined output or logged to a file for later analysis. Here’s how to log statistics every 10 seconds into a file:

vmstat 10 | tee vmstat_output.txt

Combining with grep:

vmstat 1 10 | grep -w r

This filters the output to show only lines containing the word “r” which pertains to the r column indicating the number of processes waiting for run time.

  • iostat: Similar to vmstat, but focused more narrowly on input/output statistics.
  • mpstat: Reports CPU statistics.
  • free: Displays the total amount of free and used physical and swap memory in the system.

For further reading and deeper insights into each options and outputs, consult the official documentation or the man page (man vmstat). This will provide a comprehensive guide and additional parameters that can be used with vmstat.