Enhancing Skills

vmstat: System virtual memory statistics

Command: vmstat

The vmstat command provides system information related to virtual memory, processes, paging, block IO, traps, and CPU activity. It’s useful for monitoring system performance and diagnosing issues related to memory and process management.


Sample Commands and Outputs:

  • Command: vmstat Sample Command:
  $ vmstat

Sample Output:

  [vmstat output starts]
    procs      memory    swap          io    system         cpu
   r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id
   1  0  10240  20480  40960  81920    0    0     2     5   50   70  5  3 92
   0  0  10240  20480  40960  81920    0    0     0     0   10   15  1  1 98
  [vmstat output ends]

Description:

  • procs: Information about processes
    • r: Number of processes waiting for run time
    • b: Number of processes in uninterruptible sleep
  • memory: Memory statistics
    • swpd: Amount of virtual memory used (in KB)
    • free: Amount of idle memory (in KB)
    • buff: Amount of memory used as buffers (in KB)
    • cache: Amount of memory used as cache (in KB)
  • swap: Swap space statistics
    • si: Amount of memory swapped in from disk (in KB/s)
    • so: Amount of memory swapped out to disk (in KB/s)
  • io: I/O statistics
    • bi: Number of blocks received from a block device (in KB/s)
    • bo: Number of blocks sent to a block device (in KB/s)
  • system: System statistics
    • in: Number of interrupts per second
    • cs: Number of context switches per second
  • cpu: CPU statistics
    • us: Time spent in user space (percentage)
    • sy: Time spent in system space (percentage)
    • id: Time spent idle (percentage)

Options:

  • -s [seconds]: Set the delay between updates (e.g., vmstat -s 5 updates every 5 seconds).
  • -a: Show active and inactive memory statistics.
  • -d: Show disk statistics.

Example with Options:

  • Command: vmstat -s Sample Command:
  $ vmstat -s

Sample Output:

  [vmstat -s output starts]
    10240 K total memory
    20480 K free memory
    40960 K buffer memory
    81920 K cache memory
    10240 K swap total
    20480 K swap free
  [vmstat -s output ends]

Description:

  • Provides a summary of memory and swap usage, including total, free, and buffer/cache memory.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.