Quick Memory Check Commands for Linux Servers

Essential commands to check memory usage right now. See total RAM, available memory, swap usage, and top memory-consuming processes.

Last updated: 2025-12-16

Quick Memory Check Commands for Linux Servers

Need to quickly check memory usage? Here are the essential commands for immediate memory status.

For understanding what the numbers mean, see Understanding Linux Memory.

The 3 Essential Memory Commands

# 1. Overall memory status
free -h

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

# 3. Memory with details (alternative to free)
cat /proc/meminfo | head -10

Quick Interpretation

$ free -h
              total   used   free  shared  buff/cache  available
Mem:           16Gi   12Gi  500Mi   256Mi       3.5Gi      3.2Gi
Swap:           2Gi   100Mi  1.9Gi

Quick health check:

  • available > 10% of total = OK
  • ⚠️ available < 10% of total = Monitor closely
  • 🚨 Swap usage high + available low = Memory pressure

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: Basic 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 Manual Memory Checks

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 During Manual Checks

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?

You can use Zuzia.app to add multiple servers and run the same memory check commands on each host. Each server executes commands independently, and all results are stored in Zuzia.app's database for centralized monitoring and analysis, making it easy to compare memory usage across your infrastructure.

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

If you use Zuzia.app's full package, AI analysis 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.

Note: The content above is part of our brainstorming and planning process. Not all described features are yet available in the current version of Zuzia.

If you'd like to achieve what's described in this article, please contact us – we'd be happy to work on it and tailor the solution to your needs.

In the meantime, we invite you to try out Zuzia's current features – server monitoring, SSL checks, task management, and many more.

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