Sagar.BlogArticle
All posts
All posts
Linux

System Monitoring — Track CPU, Memory and I/O

Monitor system resources in real time using free, vmstat, iostat, and sar to understand performance and spot bottlenecks.

March 29, 20255 min read
linuxsysadminmonitoringperformancevmstat

free — Memory Usage

free                         # Memory in bytes
free -h                      # Human-readable (MB/GB)
free -h -s 5                 # Update every 5 seconds
# Output example:
#               total   used   free   shared  buff/cache  available
# Mem:           15Gi   4.0Gi  8.2Gi    234Mi       3.5Gi     11Gi
# Swap:         2.0Gi      0B  2.0Gi

# "available" = memory you can actually use (includes reclaimable cache)

vmstat — Virtual Memory Statistics

vmstat                       # Single snapshot
vmstat 2                     # Update every 2 seconds
vmstat 2 10                  # 10 updates, 2 seconds apart

Key vmstat columns: r (run queue), b (blocked), si/so (swap in/out), us/sy (user/system CPU %), id (idle %).

iostat — Disk I/O Statistics

iostat                       # CPU + disk I/O snapshot
iostat -x                    # Extended disk stats
iostat -x 2                  # Update every 2 seconds
iostat -d sda                # Specific disk only

# Install if missing
sudo apt install sysstat

sar — System Activity Report

sar -u 2 5                   # CPU: every 2s, 5 times
sar -r 2 5                   # Memory: every 2s, 5 times
sar -d 2 5                   # Disk: every 2s, 5 times
sar -n DEV 2 5               # Network: every 2s, 5 times

Quick Health Check

# One-liner system overview
echo "=== CPU Load ===" && uptime && echo "=== Memory ===" && free -h && echo "=== Disk ===" && df -h /

High sy (system CPU) in vmstat often indicates kernel/I/O overhead. High wa (wait) on top means processes are waiting for disk.

Quick Check

In `free -h` output, which column shows memory you can actually allocate?

Exercise

Run vmstat 2 5 to get 5 readings 2 seconds apart. Watch the CPU idle (id) percentage column.