SoFunction
Updated on 2025-04-11

Example method for monitoring system performance using vmstat in Linux

Introduction

LinuxInvmstat(Virtual Memory Statistics) commands are used to monitor system performance, including CPU usage, memory usage, swap activity, disk I/O, and system processes. It provides real-time performance metrics that help diagnose system bottlenecks.

Basic syntax

vmstat [options] [delay] [count]
  • delay: The interval between updates (in seconds)

  • count: The number of times the command was run before it was stopped

Example usage

Run vmstat without parameters

This will display a report containing system statistics since the last restart

vmstat

Output example

Updated every 2 seconds, 5 times in total

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  50000  12000 800000    0    0     3     5  120  300  5  2 90  3  0
 0  0       0  51000  11500 805000    0    0     2     4  115  290  4  1 94  1  0

Field explanation

  • Process:procs

    • r: Number of running processes
    • b: Number of processes in a state of uninterruptible sleep
  • Memory:memory

    • swpd: Switch memory used (KB)
    • free: Available memory (KB)
    • buff: Buffered memory (KB)
    • cache: Cache memory (KB)
  • Swap:swap

    • si: Swap into memory (KB/sec)
    • so: Swap out memory (KB/sec)
  • I/O:io

    • bi: Blocks received from block device (KB/s)
    • bo: Number of blocks sent to the block device (KB/s)
  • System:system

    • in: Number of interrupts per second
    • cs: Number of context switches per second
  • CPU:cpu

    • us: User CPU usage percentage
    • sy: System (core) CPU usage percentage
    • id: idle CPU percentage
    • wa: Percentage of CPU waiting for I/O
    • st: Percentage of CPU stolen by hypervisor (relevant to virtualized environments only)

Real-time monitoring of system performance

Updated every 1 second, indefinitely

vmstat 1

Limit the number of reports

Updated every 2 seconds, run 5 times

vmstat 2 5

Displayed in megabytes instead of kilobytes

use-S MDisplay values ​​in megabytes

vmstat -S M 1 5

Monitor disk activity

Display disk I/O statistics

vmstat -d

Show detailed CPU statistics

Show summary of various system statistics

vmstat -s

Monitor NUMA (Non-Ununified Memory Access) Nodes

Show active and inactive memory

vmstat -a

Comparison with other tools

Order characteristic
top Real-time CPU and memory usage for each process
htop Interactive version of top
iostat Detailed disk I/O statistics
free Memory usage details
sar Advanced system performance monitoring

The above is the detailed content of the example method of Linux using vmstat to monitor the performance of the system. For more information about the performance of Linux vmstat, please pay attention to my other related articles!