Linux/Unix: System Performance Monitoring – top, vmstat, iostat, sar, dstat Explained

Introduction – Why Monitor Linux System Performance?

Monitoring performance is critical for preventing slowdowns, detecting bottlenecks, and ensuring system health. Linux provides powerful CLI tools to track CPU, memory, disk, and process usage in real-time or via logs. Tools like top, vmstat, iostat, sar, and dstat give deep insights into system behavior with minimal overhead.

In this guide, you’ll learn:

  • How to monitor system metrics using essential performance tools
  • When to use each command and how to interpret the output
  • Real-world examples for diagnosing issues

1. top – Real-Time System Resource Monitor

What is top?

top shows real-time CPU, memory, and process usage. It’s like a task manager for Linux.

Syntax:

top

Output Breakdown:

ColumnMeaning
PIDProcess ID
USEROwner of the process
%CPUCPU usage
%MEMRAM usage
TIME+Total CPU time
COMMANDName of the command

Example:

top

Press:

  • P to sort by CPU usage
  • M to sort by memory usage
  • k to kill a process by PID

Ideal for spotting CPU hogs or memory leaks.


2. vmstat – Memory & CPU Overview

What is vmstat?

vmstat reports memory, swap, I/O, system processes, and CPU statistics.

Syntax:

vmstat [interval] [count]

Example:

vmstat 2 5

Output:

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 123456  11234 543210    0    0     1     2  100  200  2  1 97  0  0

Key Fields:

  • us/sy = user/system CPU time
  • si/so = swap in/out
  • wa = I/O wait time (important!)

πŸ’½ 3. iostat – Disk I/O Monitoring

What is iostat?

iostat shows CPU and disk input/output stats, helping identify disk bottlenecks.

Install:

sudo apt install sysstat     # Debian/Ubuntu
sudo yum install sysstat     # RHEL/CentOS

Syntax:

iostat -xz 2 3

Output:

Device:    tps   kB_read/s  kB_wrtn/s  %util
sda        1.2       102.5       30.1   5.67

%util > 70% = disk saturation
await > 20ms = disk lag


4. sar – Historical System Statistics

What is sar?

sar collects, reports, and saves system performance data over time. Great for trend analysis.

Install:

sudo apt install sysstat

Enable service:

sudo systemctl enable --now sysstat

Syntax:

sar [option] [interval] [count]

Examples:

CPU usage:

sar -u 1 5

Memory usage:

sar -r 1 3

View logs from yesterday:

sar -u -f /var/log/sysstat/sa$(date +%d --date="yesterday")

Ideal for offline troubleshooting.


5. dstat – All-in-One Real-Time System Monitor

What is dstat?

dstat replaces vmstat, iostat, netstat, and ifstat, offering real-time stats in one view.

Install:

sudo apt install dstat

Syntax:

dstat -cdnm

Output:

----cpu---- --dsk/total-- ---net/eth0-- ---memory---
usr sys idl| read  writ| recv  send| used  buff  cach
  3   2  95 |  1kB   0kB |  0kB   0kB | 1.2G  56M  452M

Combine options:

  • -c β†’ CPU
  • -d β†’ Disk
  • -n β†’ Network
  • -m β†’ Memory

Tool Comparison Table

ToolUse CaseReal-TimeHistoricalBest For
topProcess-level monitoringCPU/memory usage per process
vmstatMemory, swap, CPU snapshotQuick system overview
iostatDisk I/O and utilizationDetecting disk bottlenecks
sarTime-series performance data/Logging system performance
dstatAll-in-one live dashboardUnified system stats in CLI

Summary – Recap & Next Steps

Linux performance tools give you everything from live diagnostics to historical trend analysis. Whether you’re tracking disk performance, memory usage, or CPU spikes, these tools help you pinpoint the issue fast.

Key Takeaways:

  • Use top to find heavy processes quickly.
  • Use vmstat for quick memory/CPU load snapshots.
  • Use iostat and dstat for disk I/O investigation.
  • Use sar for long-term performance monitoring.

FAQs

What’s the best tool to detect memory leaks?
Use top or htop to find increasing %MEM over time.

How to monitor disk usage in real time?
Use:

iostat -xz 2 5

How do I log performance data for later analysis?
Use sar (with sysstat) which logs data to /var/log/sysstat.

What’s the difference between top and htop?
htop is more visual and user-friendly but needs to be installed manually:

sudo apt install htop

Can these tools be used in scripts?
Yes. Tools like vmstat, iostat, and sar work well with automation and cron jobs.


Share Now :
Share

πŸ”΅ Linux/Unix: System Performance (top, vmstat, iostat, sar, dstat)

Or Copy Link

CONTENTS
Scroll to Top