Innovate | Connect | Transform
ContactService statusUSD $

GICT knowledge base

How to Use vmstat to Check on the Health of Your System

Published

LinuxLinux and Commands

When your computer starts acting up-maybe it’s running slow, lagging during simple tasks, or just doesn’t feel as snappy as usual-it’s natural to wonder what’s going on behind the scenes. Is your CPU maxed out? Are you running out of memory? Is your disk working overtime? If you’re using Linux, you have a powerful ally built right into your toolbox: the vmstat command.

vmstat stands for “virtual memory statistics,” but don’t let the name fool you. It’s much more than just a memory monitor. With a single glance, you can get insights into your system’s memory usage, CPU performance, processes, disk I/O, and even swapping activity. It’s like having a doctor’s stethoscope for your computer, letting you listen in on how healthy your system really is.

In this guide, you’ll learn what vmstat does, how to install and run it, and-most importantly-how to make sense of its output. Whether you’re troubleshooting a sluggish server, optimizing performance, or just curious about what’s going on, this guide will give you the confidence to use vmstat like a pro.

Prerequisites

Before you get started, you’ll want:

  • Access to a Linux system (any major distribution)
  • A user account with terminal access (root privileges not required for basic monitoring)
  • A willingness to dig into some data

No complex setup is needed-vmstat is lightweight and ready to go on most systems.

What Is vmstat and Why Should You Care?

Think of vmstat as your all-in-one system health dashboard. It taps into the Linux kernel’s statistics and presents them in a compact, easy-to-read table. While modern, graphical tools like GNOME System Monitor or htop are great, there’s a reason seasoned administrators keep coming back to vmstat: it’s fast, works over SSH, and gives you the big picture in seconds.

But why bother learning another command? Here are a few reasons:

  • Diagnose Performance Issues: Quickly identify bottlenecks in CPU, memory, or disk.
  • Spot Trends: Watch how your system behaves over time, not just in a single snapshot.
  • Low Overhead: Uses minimal resources-perfect for remote or headless servers.
  • Script-Friendly: Great for automation and logging.

If you want to know why your server suddenly feels sluggish or if you’d like to catch a problem before it becomes a crisis, vmstat is one of the best places to start.

Installing vmstat

On most Linux distributions, vmstat comes pre-installed as part of the procps or procps-ng package. To check if you have it, just type:

vmstat --version

If you see version information, you’re good to go. If not, here’s how to install it.

On Ubuntu and Debian

sudo apt update
sudo apt install procps

On CentOS, Fedora, or RHEL

sudo dnf install procps-ng

or, on older systems:

sudo yum install procps-ng

Running vmstat: Your First Look

At its most basic, running vmstat with no arguments gives you a single snapshot of your system’s performance:

vmstat

Here’s what you might see:

procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 2  0      0  98000  12000  58000    0    0     0     1   12   24  2  1 97  0  0

That might look intimidating at first, but don’t worry-we’ll break it down line by line.

Understanding the vmstat Output

Let’s walk through the columns you’ll see:

Process Columns

  • r: Number of processes waiting for CPU time (run queue).
  • b: Number of processes in uninterruptible sleep (usually waiting on I/O).

If “r” is high, your CPU is likely overworked. If “b” is high, the system is waiting on disk or network.

Memory Columns

  • swpd: Amount of virtual memory used (swap).
  • free: Free memory in kilobytes.
  • buff: Memory used as buffers for raw disk I/O.
  • cache: Memory used as cache for files.

Don’t panic if “free” is low-Linux uses available RAM for caching to speed things up. What matters is whether it frees up memory efficiently when needed.

Swap Columns

  • si: Swap in-amount of memory swapped in from disk per second.
  • so: Swap out-amount of memory swapped out to disk per second.

Consistent, non-zero values here can indicate that your system is struggling with insufficient memory.

IO Columns

  • bi: Blocks received from a block device (per second).
  • bo: Blocks sent to a block device (per second).

These numbers climb during heavy disk activity.

System Columns

  • in: Number of interrupts per second.
  • cs: Number of context switches per second.

High numbers may be normal under load, but sudden spikes can indicate a thrashing system or misbehaving driver.

CPU Columns

  • us: Time spent running non-kernel code (user time).
  • sy: Time spent running kernel code (system time).
  • id: Idle time.
  • wa: Time waiting for I/O.
  • st: Time stolen from this VM by the hypervisor (for virtualized systems).

If “wa” is high, your system is waiting on disk or network resources. If “us” and “sy” are high, your CPU is working hard.

Real-Time Monitoring with vmstat

A single snapshot is useful, but often you want to see how your system changes over time. That’s where interval mode comes in. Run:

vmstat 2

This command updates the output every two seconds. You can stop it anytime with Ctrl+C. Want more data over a specific period? Add a count:

vmstat 2 10

Here, vmstat will print statistics every two seconds, stopping after ten reports.

Watching the numbers change in real time is often the best way to spot problems as they develop.

Practical Examples and Use Cases

Let’s look at some scenarios where vmstat can help you diagnose and solve real-world problems.

1. Diagnosing a Slow System

Suppose your server starts lagging-web pages take ages to load, or terminal commands hang for seconds. Open a terminal and run:

vmstat 1

Watch the “wa” (I/O wait) and “r” (run queue) columns. If “wa” shoots up, your server is likely waiting on the disk. If “r” is high, you may be CPU-bound.

2. Detecting Memory Pressure

Running out of RAM? Check the “si” and “so” columns. Any consistent swapping activity means your system is moving memory to and from disk, which is slow. If you see these values creeping up, it’s a sign you need more RAM or fewer running processes.

3. Spotting Disk or Network Bottlenecks

Keep an eye on “bi” and “bo.” If these numbers skyrocket during heavy usage, your disk is working overtime. Pair this with high “wa” and you’ve identified a classic bottleneck.

4. Monitoring Virtual Machines

If you’re running Linux inside a VM, the “st” (steal time) column tells you if your VM is losing CPU cycles to other VMs. High “st” means the hypervisor is busy, and your VM isn’t getting enough CPU time.

Making Sense of Buffers and Cache

Linux manages memory differently than some other operating systems. It tries to use all available RAM for caching files and buffers to speed up operations. That’s why you might be shocked to see “free” memory so low. However, this is normal-and healthy! When a running program needs more memory, Linux quickly reclaims what it needs from the cache. So unless you’re actively swapping, you’re in good shape.

Advanced vmstat Options

There’s more to vmstat than the default output. Here are some handy options:

Display Disk Statistics

On many systems, you can use the -d flag for disk statistics:

vmstat -d

This shows read and write activity for each disk device.

Show Slabinfo

The slab allocator manages memory caches for the kernel. Use:

vmstat -m

You’ll see detailed stats about kernel memory usage.

Report Fork Activity

Want to see how often new processes are created? Try:

vmstat -f

This displays the number of forks since boot.

Per-CPU Statistics

If your system has more than one CPU core, you can break down usage by core:

vmstat -S M 1

Here, -S M shows output in megabytes, and the interval lets you spot differences across CPUs.

Automating System Health Checks with vmstat

One of the great things about vmstat is how easily you can incorporate it into scripts. For example, you might want to log system performance every minute:

* * * * * vmstat 1 2 >> /var/log/vmstat.log

This cron job records two samples (to filter out the initial boot-up average) every minute, appending them to a log. Reviewing these logs over time can help you spot gradual changes before they turn into problems.

Troubleshooting Checklist with vmstat

Here’s a quick reference when something goes wrong:

  • System Feels Slow: Check “r” and “wa.” High “r” means CPU is busy; high “wa” points to disk or network.
  • Running Out of Memory: Look for non-zero “si” and “so.” Frequent swapping slows everything down.
  • Disk is Slow: High “bi/bo” and “wa” together indicate a storage bottleneck.
  • Virtual Machine Feels Sluggish: Check “st.” If this is high, your VM needs more resources from the host.

Comparing vmstat to Other Monitoring Tools

You might wonder, “Why use vmstat when tools like top, htop, or glances exist?” Here’s how it stacks up:

  • vmstat: Fast, scriptable, and gives big-picture trends.
  • top/htop: Real-time, interactive; best for zooming in on individual processes.
  • free: Focuses on memory, but less detail about processes or CPU.
  • iostat: Great for detailed disk I/O stats.

The best approach? Use them together! Start wide with vmstat, then zero in with top or htop as needed.

Real-World Story: Catching a Sneaky Memory Leak

Let’s say you’re managing a web server that starts to crawl after a few days of uptime. You suspect a memory leak. Running vmstat 10, you watch as “free” memory slowly drops, while “si” and “so” (swap in/out) stay at zero. That’s normal. But suddenly, after a few hours, you see “si” and “so” spike, and “free” hits rock bottom.

That’s your clue: something is eating up memory until the system has to swap. By combining vmstat with ps or top, you can hunt down the offending process and fix the leak before your users even notice.

Tips for Getting the Most Out of vmstat

  • Run vmstat at different times of day to spot patterns.
  • Use interval mode (vmstat N) for real-time troubleshooting.
  • Don’t panic if “free” memory is low-check swap activity and caches before worrying.
  • Combine vmstat with dmesg, free, iostat, and top for a holistic view.
  • Log output over time for trending and historical analysis.

Frequently Asked Questions

Why Do I See Low Free Memory?
Linux uses unused RAM to cache data, making your system faster. It will free up memory for applications as needed, so low “free” memory is usually not a problem. Worry only if swapping is happening.

Is vmstat Available on macOS or Windows?
Out of the box, no. macOS offers similar tools like vm_stat, and Windows has Task Manager and Resource Monitor.

How Do I Check Only Disk or Memory Statistics?
Use vmstat -d for disk, or vmstat -s for a summary of memory statistics.

Can I Use vmstat in Scripts?
Absolutely! Its simple, predictable output makes it perfect for automation and monitoring scripts.

Conclusion

The vmstat command is one of the most powerful tools at your disposal for understanding and maintaining the health of your Linux system. It provides a snapshot-or a moving picture-of how your CPU, memory, disks, and processes are behaving, all in a concise table that reveals the big picture at a glance.

By learning to interpret vmstat’s output, you put yourself in control of your system’s health. Whether you’re solving a problem, optimizing performance, or just satisfying your curiosity, you’ll find that a quick look at vmstat often gives you the answer you need.

When trouble strikes, don’t just guess-grab your terminal, run vmstat, and let your system tell you what’s really going on.

Related guides

Account services are unavailable until the production backend is configured.