In this eighth part of our Linux 101 series, we will explore System Monitoring and Performance Tuning to help optimize system resources, troubleshoot issues, and improve efficiency.
Why Monitor System Performance?
Monitoring system performance allows you to:
- Detect and troubleshoot slowdowns.
- Optimize resource usage.
- Prevent system crashes and failures.
- Ensure servers run efficiently.
Essential System Monitoring Commands
1. Checking System Load and CPU Usage
- View real-time CPU and process usage:
top - Enhanced process monitoring (interactive UI):
(Install htop if not available:htopsudo apt install htoporsudo dnf install htop) - Check CPU load averages:
uptime
2. Checking Memory Usage
- View memory usage in MB:
free -m - Detailed memory usage analysis:
(Refreshes every 5 seconds)vmstat 5
3. Checking Disk Usage
- Check disk space usage:
df -h - Check which folders use the most space:
du -sh /home/*
4. Monitoring Running Processes
- List running processes:
ps aux - Find a specific process:
ps aux | grep processname - Kill a high-resource-consuming process:
kill PID
5. Checking Network Usage
- View active network connections:
netstat -tulnp - Monitor real-time network usage:
(Install withiftopsudo apt install iftoporsudo dnf install iftop)
Performance Tuning in Linux
1. Optimizing CPU Performance
- Change process priority using
niceandrenice:nice -n 10 commandrenice -n -5 -p PID - Limit CPU usage of a process:
(Install withcpulimit -p PID -l 50sudo apt install cpulimit)
2. Managing RAM and Swap Space
- Clear cached memory:
sync; echo 3 > /proc/sys/vm/drop_caches - Check swap usage:
swapon -s - Increase swap space:
sudo fallocate -l 2G /swapfile sudo chmod 600 /swapfile sudo mkswap /swapfile sudo swapon /swapfile
3. Improving Disk Performance
- Enable write caching:
sudo hdparm -W1 /dev/sda - Check disk health:
(Install withsudo smartctl -a /dev/sdasudo apt install smartmontools)
4. Managing Services and Startup Applications
- List enabled services:
systemctl list-units --type=service - Disable unwanted services:
sudo systemctl disable service-name - View startup applications:
systemd-analyze blame
Automating Performance Monitoring
You can automate system monitoring with tools like cron jobs and log monitoring:
- Log system resource usage every 10 minutes:
Add this line:crontab -e*/10 * * * * free -m >> /var/log/memory.log - Monitor CPU and memory with
sar(install withsudo apt install sysstat):sar -u 5 10
Conclusion
System monitoring and performance tuning are essential for maintaining a stable Linux environment. In the next part, we will explore Backup and Recovery Strategies in Linux to ensure data protection and disaster recovery planning.
Stay tuned for Linux 101: Part 9 – Backup and Recovery Strategies in Linux!

0 comments:
Post a Comment