How to Monitor System Load Average Periodically in Linux
Learn how to monitor CPU load average and memory usage in Linux using simple while loops. A lightweight alternative to top command for system administrators.
Monitoring system performance is a critical task for system administrators and developers. While the top command provides comprehensive resource information, sometimes you need a lighter, more focused approach to track specific metrics over time. This guide demonstrates how to create a simple monitoring loop to periodically check CPU load average and memory usage.
Understanding the Need
When troubleshooting performance issues or monitoring system behavior during specific operations, you may want to:
- Track CPU load trends without the overhead of full system monitoring tools
- Record memory and swap usage at regular intervals
- Create a lightweight monitoring solution that can run in the background
- Capture snapshots of system state for later analysis
The Solution: Using a While Loop
Instead of continuously watching top, we can create a simple loop that checks specific metrics at defined intervals. This approach uses the while true construct combined with standard Linux commands.
Basic Syntax
while true; do
date
cat /proc/loadavg
free
sleep 600
doneBreaking Down the Command
while true: Creates an infinite loop that continues until manually stoppeddate: Displays the current timestamp for each checkcat /proc/loadavg: Shows the 1-minute, 5-minute, and 15-minute load averagesfree: Displays memory and swap usage statisticssleep 600: Pauses for 600 seconds (10 minutes) between checks
Example Output
Here’s what the monitoring output looks like:
[user@server ~]$ while true; do
date
cat /proc/loadavg
free
sleep 600
done
Mon Jan 25 18:52:26 CST 2026
16.80 9.99 4.23 17/760 473640
total used free shared buff/cache available
Mem: 49065224 32839616 763044 13857116 29796508 16225608
Swap: 24731644 1896372 22835272
Mon Jan 25 19:02:26 CST 2026
17.12 16.02 10.29 7/759 473766
total used free shared buff/cache available
Mem: 49065224 33099712 787048 13891812 29546760 15965512
Swap: 24731644 1809076 22922568
Mon Jan 25 19:12:26 CST 2026
17.28 17.16 13.63 4/760 473838
total used free shared buff/cache available
Mem: 49065224 33306620 845572 13908896 29298320 15758604
Swap: 24731644 1720500 23011144
...Interpreting the Results
Load Average Values
The three numbers in /proc/loadavg represent:
- First number: 1-minute load average
- Second number: 5-minute load average
- Third number: 15-minute load average
A load average higher than your number of CPU cores typically indicates the system is under stress.
Memory Information
The free command shows:
- Total: Total installed memory
- Used: Memory currently in use
- Free: Completely unused memory
- Buff/cache: Memory used for buffers and cache
- Available: Memory available for new applications (more accurate than “free”)
Stopping the Monitor
To stop the monitoring loop, simply press Ctrl + C in the terminal. This sends an interrupt signal that terminates the loop.
Customization Options
Adjust the Monitoring Interval
Change the sleep value to modify how frequently checks occur:
sleep 300 # Check every 5 minutes
sleep 60 # Check every minute
sleep 3600 # Check every hourAdd Additional Metrics
You can expand the monitoring to include other system information:
while true; do
date
echo "=== Load Average ==="
cat /proc/loadavg
echo "=== Memory Usage ==="
free -h
echo "=== Disk Usage ==="
df -h
echo "=== Top Processes ==="
ps aux --sort=-%cpu | head -6
sleep 600
doneSave Output to a File
Redirect the output to a file for later analysis:
while true; do
date
cat /proc/loadavg
free
sleep 600
done >> system_monitor.log 2>&1Using in Shell Scripts
This technique is particularly useful when incorporated into shell scripts for automated monitoring:
#!/bin/bash
# system_monitor.sh - Simple system monitoring script
LOG_FILE="/var/log/custom_monitor.log"
INTERVAL=600 # 10 minutes
while true; do
{
echo "===================="
date
echo "Load Average:"
cat /proc/loadavg
echo "Memory Status:"
free -h
echo ""
} >> "$LOG_FILE"
sleep "$INTERVAL"
doneMake the script executable and run it in the background:
chmod +x system_monitor.sh
nohup ./system_monitor.sh &Best Practices
- Choose appropriate intervals: Very frequent checks can consume resources; balance monitoring needs with system overhead
- Log rotation: If saving to files, implement log rotation to prevent disk space issues
- Use meaningful timestamps: Include date and time for easier troubleshooting
- Monitor during specific events: Run the loop during database migrations, application deployments, or load testing
- Combine with alerts: Parse the output to trigger notifications when thresholds are exceeded
Conclusion
This simple monitoring approach provides a lightweight alternative to full-featured monitoring tools when you need focused, periodic system checks. The flexibility of the while loop allows you to customize exactly what you monitor and how often, making it an invaluable tool in any system administrator’s toolkit.
Whether you’re troubleshooting performance issues, establishing baseline metrics, or monitoring system behavior during specific operations, this technique offers a quick and effective solution without the complexity of enterprise monitoring systems.


