Effective system monitoring is crucial for maintaining healthy Linux systems. This guide covers essential tools for monitoring system resources.
Table of Contents
Open Table of Contents
Disk Usage Monitoring
Check Filesystem Space
df -h
Output:
$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 98G 48G 45G 52% /
/dev/sda2 146G 98G 41G 71% /home
Directory Size Analysis
du -sh */
Memory Management
View Memory Usage
free -m
Output:
$ free -m
total used free shared buff/cache available
Mem: 15951 4589 7855 524 3506 10582
Swap: 2047 0 2047
Interactive Quiz
Question 1
How would you find the top 5 largest directories in /home?
Click to see answer
du -h /home | sort -rh | head -n 5
Question 2
What command shows real-time CPU and memory usage?
Click to see answer
top
# or
htop
Performance Analysis
CPU Usage
mpstat 1
I/O Statistics
iostat -x 1
Best Practices
- Regular monitoring schedule
- Set up alerting thresholds
- Keep historical data
- Monitor all critical systems
- Document baseline performance
Practical Examples
Find Large Files
find / -type f -size +100M -exec ls -lh {} \;
Monitor System Load
watch -n 1 'cat /proc/loadavg'
Complete System Analysis Script
#!/bin/bash
echo "=== System Resources Overview ==="
date
echo -e "\n=== Disk Usage ==="
df -h
echo -e "\n=== Memory Usage ==="
free -m
echo -e "\n=== CPU Load ==="
uptime
echo -e "\n=== Most Memory Intensive Processes ==="
ps aux --sort=-%mem | head -n 5
Common Monitoring Scenarios
- High CPU Usage
top -b -n 1 | head -n 12
- Disk Space Issues
df -h | awk '{ if($5 > "80") print $0 }'
- Memory Problems
vmstat 1 5
Conclusion
Effective system monitoring is essential for maintaining reliable Linux systems. Regular monitoring and proactive management help prevent system issues.
Quick Reference Guide
Command | Purpose | Common Options |
---|---|---|
df | Disk space | -h (human readable) |
du | Directory usage | -sh (summary) |
free | Memory info | -m (megabytes) |
top | Process activity | -b (batch mode) |
iostat | I/O statistics | -x (extended) |
Complete Linux Command Line Series
- Find Command Guide
- Process Management
- Text Processing
- Network Commands
- System Monitoring (Current Article)
Additional Resources
- Linux Performance Tuning Guide
- Advanced System Administration
- Automation with Shell Scripting
- Container Monitoring