How to Monitor Swap Usage on Linux Server - Complete Guide

Are you wondering how to check swap usage on your Linux server? Need to monitor virtual memory utilization and detect when your system is running low on RAM? This comprehensive guide shows you multiple methods to check swap usage, track ...

Last updated: 2025-11-17

How to Monitor Swap Usage on Linux Server - Complete Guide

Are you wondering how to check swap usage on your Linux server? Need to monitor virtual memory utilization and detect when your system is running low on RAM? This comprehensive guide shows you multiple methods to check swap usage, track swap activity over time, identify memory pressure, and ensure your Linux server has adequate memory resources to prevent performance degradation.

Why Monitoring Swap Usage Matters

Swap space is virtual memory that Linux uses when physical RAM is full. While swap prevents out-of-memory errors, excessive swap usage indicates memory pressure and can severely degrade system performance. Monitoring swap usage helps you detect memory bottlenecks early, plan RAM upgrades proactively, and optimize memory allocation to maintain optimal server performance.

Method 1: Check Swap Usage with swapon Command

The swapon command shows information about swap partitions and files currently in use.

Basic Swap Information

To see all active swap devices:

swapon --show

This displays:

  • Swap device names
  • Swap type (partition or file)
  • Swap size
  • Used swap space
  • Priority

Alternative Format

For a simpler output format:

swapon -s

This shows the same information in a more compact format, useful for quick checks.

Check Swap Summary

To see total swap usage:

swapon --summary

This provides a summary of all swap devices and their combined usage.

Method 2: Check Swap Usage with free Command

The free command shows memory and swap usage in a human-readable format.

View Memory and Swap Together

free -h

This displays:

  • Total RAM
  • Used RAM
  • Available RAM
  • Total swap
  • Used swap
  • Available swap

Filter Swap Information Only

To see only swap information:

free -h | grep Swap

This filters the output to show only swap-related information.

Check Swap Usage in Megabytes

For precise values in megabytes:

free -m | grep Swap

This shows swap usage in MB, useful for scripts and automated monitoring.

Method 3: Check Swap Usage with /proc/swaps

The /proc/swaps file contains detailed information about swap usage.

View Swap Details

cat /proc/swaps

This shows:

  • Swap device paths
  • Swap type
  • Swap size
  • Used swap
  • Priority

Parse Swap Usage

To extract specific information:

# Total swap size
awk '/^\/dev/ {total+=$3} END {print "Total swap:", total, "KB"}' /proc/swaps

# Used swap
awk '/^\/dev/ {used+=$4} END {print "Used swap:", used, "KB"}' /proc/swaps

This allows you to parse specific swap metrics for monitoring scripts.

Method 4: Automated Swap Usage Monitoring with Zuzia.app

Manually checking swap usage works for occasional verification, but for production servers, you need automated monitoring that alerts you when swap usage exceeds thresholds. Zuzia.app provides comprehensive swap monitoring through scheduled command execution.

Setting Up Automated Swap Monitoring

  1. Add Scheduled Task in Zuzia.app Dashboard

    • Navigate to your Linux server in Zuzia.app
    • Click "Add Scheduled Task"
    • Choose "Command Execution" as the task type
  2. Configure Swap Check Command

    • Enter command: free -h | grep Swap
    • Set execution frequency: Every 30 minutes (recommended)
    • Configure alert conditions: Alert when swap usage > 50%
    • Set up different thresholds for warning vs. critical
  3. Set Up Notifications

    • Choose notification channels (email, webhook, Slack, etc.)
    • Configure alert thresholds (e.g., alert if swap usage > 50%)
    • Set up escalation rules for high swap usage

Monitor Swap Usage Percentage

Calculate swap usage percentage:

# Get swap usage percentage
free | grep Swap | awk '{if ($2 > 0) printf "%.1f%%\n", ($3/$2)*100; else print "0%"}'

Add this to Zuzia.app to track swap usage percentage over time and receive alerts when thresholds are exceeded.

Zuzia.app stores all command outputs in its database, allowing you to track swap usage trends over time. You can see historical data showing how swap usage changes throughout the day, identify patterns in memory pressure, and plan RAM upgrades based on trends.

Method 5: Advanced Swap Monitoring Techniques

Compare Swap with RAM Usage

Understanding the relationship between RAM and swap helps identify memory pressure:

# Show both RAM and swap
free -h

# Calculate memory pressure
free | awk '/^Mem/ {mem_used=$3; mem_total=$2} /^Swap/ {swap_used=$3; swap_total=$2} END {if (mem_total > 0) printf "RAM usage: %.1f%%, Swap usage: %.1f%%\n", (mem_used/mem_total)*100, (swap_used/swap_total)*100}'

This helps you understand overall memory pressure, not just swap usage.

Monitor Swap Activity

Check if swap is actively being used:

# Check swap I/O
vmstat 1 5 | grep si

High swap-in (si) values indicate the system is actively reading from swap, which significantly impacts performance.

Check Swap Configuration

Verify swap configuration:

# List swap devices
swapon --show

# Check swap priority
cat /proc/swaps

Understanding swap configuration helps optimize memory management.

Real-World Use Cases for Swap Monitoring

Memory Pressure Detection

Monitor swap usage to detect memory pressure early:

# Check swap usage
free -h | grep Swap

# Alert if swap usage > 50%
free | grep Swap | awk '{if ($2 > 0 && ($3/$2)*100 > 50) print "High swap usage!"}'

Set up Zuzia.app to check swap usage every 30 minutes and alert when usage exceeds 50%, indicating potential memory pressure.

RAM Upgrade Planning

Track swap usage trends to plan RAM upgrades:

# Daily swap usage check
free -h | grep Swap > /tmp/swap-$(date +%Y%m%d).txt

Store swap usage data in Zuzia.app to identify trends. Consistently high swap usage indicates you need more RAM.

Performance Optimization

Monitor swap usage to optimize application memory usage:

# Check swap usage before and after optimization
free -h | grep Swap

Compare swap usage before and after optimizing applications to measure improvement.

Capacity Planning

Use historical swap usage data to plan server capacity:

# Track peak swap usage
free | grep Swap | awk '{print $3}'

Zuzia.app's historical data helps you understand peak memory requirements and plan server capacity accordingly.

Best Practices for Swap Monitoring

1. Monitor Swap Usage Regularly

Check swap usage at least every 30 minutes to 1 hour. Swap usage changes more slowly than RAM usage, but regular monitoring helps detect trends early.

2. Set Appropriate Thresholds

Set different alert thresholds for different scenarios:

  • Warning: Swap usage > 30%
  • Critical: Swap usage > 50%
  • Emergency: Swap usage > 80%

3. Compare Swap with RAM Usage

Don't monitor swap in isolation. Compare swap usage with RAM usage to understand overall memory pressure. High swap usage with low RAM usage might indicate memory leaks.

4. Track Swap Activity, Not Just Usage

Monitor swap activity (swap-in/swap-out) in addition to usage. High swap activity indicates active memory pressure, even if current usage is moderate.

5. Use Historical Data for Planning

Use Zuzia.app's historical data to identify patterns. Understanding when swap usage peaks helps you plan maintenance windows and capacity upgrades.

Troubleshooting Common Swap Monitoring Issues

Swap Usage Shows Zero

If swap usage always shows zero:

  1. Check if swap is enabled: swapon --show
  2. Verify swap configuration: cat /proc/swaps
  3. Check if swap was disabled: swapoff -a would disable all swap

High Swap Usage but System Seems Fine

If swap usage is high but system performance is acceptable:

  1. Check swap activity: vmstat 1 5
  2. Verify RAM usage: free -h
  3. Check if swap is being used actively or just allocated

Swap Usage Increasing Over Time

If swap usage is gradually increasing:

  1. Check for memory leaks in applications
  2. Monitor RAM usage trends
  3. Review application memory allocation
  4. Consider RAM upgrade if trend continues

FAQ: Common Questions About Monitoring Swap Usage

How often should I check swap usage on Linux?

We recommend checking swap usage every 30 minutes to 1 hour. Swap usage changes more slowly than RAM usage, but regular monitoring helps detect memory pressure trends early. Use Zuzia.app automated monitoring to check swap usage continuously without manual intervention.

What does high swap usage indicate?

High swap usage typically indicates insufficient RAM for the current workload. When physical RAM is full, Linux uses swap space (virtual memory on disk), which is much slower than RAM. High swap usage can severely degrade system performance, so it's a sign you may need more RAM or to optimize memory usage.

Can I see swap usage history over time?

Yes, Zuzia.app stores all swap usage data historically in its database, allowing you to view trends and identify patterns. You can see historical data showing how swap usage changes throughout the day, week, or month, helping you plan RAM upgrades and optimize memory allocation.

What should I do if swap usage is consistently high?

If swap usage is consistently high, investigate memory usage patterns and consider planning a RAM upgrade. High swap usage indicates your system needs more physical RAM. Use Zuzia.app to track memory usage trends and identify which applications are consuming the most memory.

How do I know if swap is actively being used vs. just allocated?

Check swap activity using vmstat 1 5 and look at the swap-in (si) and swap-out (so) columns. High values indicate active swap usage, which significantly impacts performance. Low or zero values mean swap is allocated but not actively being used.

Can I monitor swap usage across multiple Linux servers?

Yes, Zuzia.app allows you to add multiple servers and monitor swap usage across all of them simultaneously. Each server executes swap check commands independently, and all results are stored in Zuzia.app's database for centralized monitoring and comparison.

Does Zuzia.app use AI to analyze swap usage patterns?

Yes, if you have Zuzia.app's full package, AI analysis is enabled. The AI can detect patterns in swap usage, predict when you'll need more RAM based on trends, and suggest optimizations to reduce memory pressure and improve system performance.

We use cookies to ensure the proper functioning of our website.