How to Check Memory Usage on Linux Server - Complete Guide

Are you wondering how to check memory (RAM) usage on your Linux server? Need to identify processes consuming the most memory and detect potential memory leaks? This comprehensive guide shows you multiple methods to monitor memory usage, ...

Last updated: 2025-11-17

How to Check Memory Usage on Linux Server - Complete Guide

Are you wondering how to check memory (RAM) usage on your Linux server? Need to identify processes consuming the most memory and detect potential memory leaks? This comprehensive guide shows you multiple methods to monitor memory usage, track memory consumption over time, identify memory-intensive processes, and ensure your Linux server has adequate RAM for optimal performance.

Why Monitoring Memory Usage Matters

Memory (RAM) is one of the most critical resources on your Linux server. High memory usage can cause performance degradation, application crashes, and system instability. Without proper monitoring, you might not notice memory issues until they cause critical failures. Regular memory monitoring helps you identify memory leaks, plan capacity upgrades, optimize resource allocation, and prevent system crashes.

Method 1: Check Memory Usage with free Command

The most straightforward way to check memory usage on Linux is using the free command. This built-in utility shows total, used, free, and available memory, as well as swap space information.

Basic Memory Check

To see current memory usage:

# Check memory usage in human-readable format
free -h

# Check memory usage in megabytes
free -m

# Check memory usage in gigabytes
free -g

This command displays:

  • Total memory installed
  • Used memory (by applications and system)
  • Free memory (completely unused)
  • Available memory (available for new processes)
  • Swap space usage

Detailed Memory Information

For more detailed memory breakdown:

# Show memory statistics
free -h -w

# Show memory with buffers and cache
free -h -t

# Continuous monitoring (update every 2 seconds)
watch -n 2 free -h

Check Swap Usage

To see swap space usage:

# Check swap usage
swapon -s

# Show swap summary
free -h | grep Swap

# Check swap usage percentage
free | awk '/^Swap:/ {printf "Swap Usage: %.1f%%\n", $3/$2*100}'

Method 2: Identify Memory-Intensive Processes

Knowing total memory usage is helpful, but identifying which processes consume the most memory is crucial for troubleshooting.

Top Memory-Consuming Processes

To see processes sorted by memory usage:

# Top 10 memory-consuming processes
ps aux --sort=-%mem | head -10

# Top memory-consuming processes with details
ps aux --sort=-%mem | head -20

# Show memory usage in MB
ps aux --sort=-%mem | awk 'NR==1 || $6/1024 > 100' | head -20

Monitor Specific Process Memory

To check memory usage of a specific process:

# Check memory usage of specific process
ps aux | grep nginx | awk '{sum+=$6} END {print sum/1024 " MB"}'

# Monitor process memory over time
watch -n 1 'ps aux | grep nginx | awk "{sum+=\$6} END {print sum/1024 \" MB\"}"'

Memory Usage by User

To see memory usage per user:

# Memory usage by user
ps aux | awk '{mem[$1]+=$6} END {for (user in mem) print user, mem[user]/1024 " MB"}'

# Top users by memory consumption
ps aux | awk '{mem[$1]+=$6} END {for (user in mem) print mem[user]/1024, user}' | sort -rn | head -10

Method 3: Automated Memory Monitoring with Zuzia.app

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

Setting Up Automated Memory Monitoring

  1. Add Scheduled Task in Zuzia.app Dashboard

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

    • Enter command: free -h
    • Set execution frequency: Every 15-30 minutes for active monitoring
    • Configure alert conditions: Alert when memory usage exceeds 80% or 90%
    • Set up thresholds for different severity levels
  3. Set Up Notifications

    • Choose notification channels (email, webhook, Slack, etc.)
    • Configure alert thresholds (e.g., warning at 80%, critical at 90%)
    • Set up escalation rules for high memory usage
    • Configure automatic actions when memory is critically high

Track memory usage over time to identify patterns:

# Save memory usage to file with timestamp
echo "$(date): $(free -h | grep Mem | awk '{print $3 "/" $2}')" >> /tmp/memory-usage.log

# Check memory usage percentage
free | awk '/^Mem:/ {printf "Memory Usage: %.1f%%\n", $3/$2*100}'

Zuzia.app stores all command outputs in its database, allowing you to track memory usage trends over time and identify patterns in memory consumption.

Method 4: Advanced Memory Monitoring Techniques

Detect Memory Leaks

Memory leaks occur when processes gradually consume more memory over time. To detect potential leaks:

# Monitor process memory over time
watch -n 5 'ps aux --sort=-%mem | head -5'

# Track specific process memory growth
while true; do ps aux | grep process-name | awk '{print $6/1024 " MB"}'; sleep 60; done

Check Memory Pressure

To see if the system is under memory pressure:

# Check memory pressure indicators
cat /proc/meminfo | grep -E "MemAvailable|MemFree|SwapFree"

# Calculate memory pressure
free | awk '/^Mem:/ {avail=$7; total=$2; printf "Memory Pressure: %.1f%%\n", (total-avail)/total*100}'

Monitor Cache and Buffer Usage

Linux uses available memory for caching. To see cache usage:

# Show cache and buffer usage
free -h | grep -E "Mem|buff/cache"

# Detailed cache information
cat /proc/meminfo | grep -E "Cached|Buffers|SwapCached"

Real-World Use Cases for Memory Monitoring

Web Server Memory Monitoring

For web servers running Nginx or Apache:

# Monitor web server memory
ps aux | grep -E "nginx|apache2" | awk '{sum+=$6} END {print sum/1024 " MB"}'

# Check if web server memory is growing
watch -n 30 'ps aux | grep nginx | awk "{sum+=\$6} END {print sum/1024 \" MB\"}"'

Set up Zuzia.app to monitor web server memory every 15 minutes and alert if memory usage exceeds thresholds.

Database Memory Monitoring

Database servers often consume significant memory:

# Monitor database memory usage
ps aux | grep -E "mysql|postgresql|mariadb" | awk '{sum+=$6} END {print sum/1024 " MB"}'

# Check database buffer pool usage
mysql -e "SHOW VARIABLES LIKE 'innodb_buffer_pool_size';"

Application Memory Monitoring

For application servers:

# Monitor application memory
ps aux | grep java | awk '{sum+=$6} END {print sum/1024 " MB"}'

# Monitor PHP-FPM memory
ps aux | grep php-fpm | awk '{sum+=$6} END {print sum/1024 " MB"}'

Best Practices for Memory Monitoring

1. Monitor Memory Regularly

Check memory usage every 15-30 minutes for active monitoring. For less critical systems, every hour is sufficient. Use Zuzia.app automated monitoring to check memory continuously without manual intervention.

2. Set Appropriate Alert Thresholds

Configure alerts at different levels:

  • Warning: 70-80% memory usage
  • Critical: 85-90% memory usage
  • Emergency: 95%+ memory usage

Use Zuzia.app's historical data to identify patterns. Memory usage that increases gradually over time might indicate memory leaks or capacity planning needs.

4. Monitor Swap Usage

High swap usage indicates insufficient RAM. Monitor swap usage and alert when swap usage exceeds 50% to identify systems that need more memory.

5. Identify Memory-Intensive Processes

Regularly review top memory-consuming processes to identify applications that might need optimization or additional resources.

Troubleshooting Common Memory Issues

High Memory Usage

If memory usage is consistently high:

  1. Identify top memory-consuming processes: ps aux --sort=-%mem | head -10
  2. Check for memory leaks by monitoring process memory over time
  3. Review application configurations for memory limits
  4. Consider adding more RAM if usage is consistently high

Memory Leaks

If you suspect memory leaks:

  1. Monitor process memory over time: watch -n 60 'ps aux --sort=-%mem | head -5'
  2. Check application logs for memory-related errors
  3. Review application code for memory management issues
  4. Restart affected processes if memory usage becomes critical

Swap Usage Issues

If swap usage is high:

  1. Check available RAM: free -h
  2. Identify memory-intensive processes: ps aux --sort=-%mem | head -10
  3. Consider adding more RAM if swap usage is consistently high
  4. Optimize applications to reduce memory consumption

FAQ: Common Questions About Checking Memory Usage

How often should I check memory usage?

We recommend checking memory usage every 30 minutes for active monitoring. For less critical systems, every hour is sufficient. Use Zuzia.app automated monitoring to check memory continuously without manual intervention.

What if memory usage is high?

You'll receive alerts when memory usage exceeds thresholds through Zuzia.app. You can then investigate which processes are consuming memory using ps aux --sort=-%mem | head -10 and take appropriate action, such as optimizing applications, restarting processes, or adding more RAM.

Can I monitor swap usage?

Yes, you can use swapon -s or free -h to check swap usage. High swap usage may indicate insufficient RAM. Monitor swap usage and alert when it exceeds 50% to identify systems that need more memory.

How do I identify memory leaks?

Monitor process memory over time using watch -n 60 'ps aux --sort=-%mem | head -5'. If a process's memory usage gradually increases without corresponding workload increases, it might indicate a memory leak. Use Zuzia.app to track memory usage trends and identify patterns.

What's the difference between free and available memory?

Free memory is completely unused RAM. Available memory includes free memory plus memory that can be freed from buffers and cache if needed. Available memory is a better indicator of memory available for new processes.

How can I monitor memory usage across multiple servers?

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

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

Yes, if you have Zuzia.app's full package, AI analysis is enabled. The AI can detect patterns in memory usage, predict potential memory issues before they occur, identify memory leaks, and suggest optimizations based on historical memory data and machine learning algorithms.

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