Monitoring memory usage in Linux is crucial for system performance and troubleshooting. Here are some essential commands to check and analyze memory usage effectively.
grep
to Detect Out-of-Memory ErrorsThe grep
command helps search system logs for out-of-memory errors:
grep -i -r 'out of memory' /var/log/
Use case: Identifies memory exhaustion issues from logs.
free -m
to Check RAM UsageThe free
command provides real-time memory usage details:
free -m
Output includes:
Total, used, and available RAM
Swap memory details
sar
for Historical Memory UsageThe sar
command displays memory usage trends over time:
sar -r
Use case: Useful for diagnosing gradual memory leaks.
top -c
to Identify Memory-Intensive ProcessesMonitor running processes and sort them by memory usage:
top -c
Tip: Press Shift + M
to sort by memory usage.
mysqladmin proc stat
for MySQL Memory AnalysisCheck MySQL queries that may be causing high memory usage:
mysqladmin proc stat
Use case: Identifies slow or stuck queries consuming RAM.
grep
to Analyze Website Access Logs (For cPanel Servers)Monitor suspicious access patterns that may lead to high memory usage:
grep -ir "05/Mar/2025:10:20" /usr/local/apache/domlogs/
Signs of abuse:
High requests from specific IPs
Excessive HTTP POST requests
Repeated failed login attempts
Efficient memory monitoring and optimization can prevent crashes and enhance system stability. Use these commands to diagnose and fix memory-related issues proactively.