High CPU usage can slow down your system. Use these commands to monitor and investigate:
| Command | Description |
|---|---|
top |
Real-time view of CPU usage by process. |
htop |
Interactive, colorful version of top with easier navigation. |
mpstat |
CPU usage per processor/core (sudo apt install sysstat on Debian/Ubuntu). |
pidstat -u |
CPU usage per process over time. |
uptime |
Shows system load averages for 1, 5, and 15 minutes. |
Tips:
- Identify processes consuming high CPU (
%CPUintop/htop). - If a process is stuck, use
kill -9 <PID>to terminate it.
Memory issues can cause slowdowns or application crashes.
| Command | Description |
|---|---|
free -h |
Shows total, used, and free memory in human-readable format. |
vmstat 1 5 |
Provides memory, swap, and CPU statistics every second (5 times). |
top / htop |
Check processes consuming high memory (%MEM). |
smem |
Advanced memory reporting per process (install if not available). |
Tips:
- Check swap usage: if swap is high, consider optimizing memory or adding swap.
- Monitor memory-hog processes and investigate leaks.
Logs help identify application or system errors.
| Log File | Description |
|---|---|
/var/log/syslog |
General system messages (Debian/Ubuntu). |
/var/log/messages |
General system messages (RedHat/CentOS). |
/var/log/kern.log |
Kernel-related messages. |
/var/log/auth.log |
Authentication logs, login attempts. |
/var/log/dmesg |
Kernel ring buffer; hardware/boot messages. |
/var/log/<service>.log |
Logs for individual services (like nginx, apache2, etc.). |
Commands for Logs:
tail -f /var/log/syslog→ Monitor log in real-time.grep "error" /var/log/syslog→ Search logs for specific keywords.journalctl -u <service>→ View logs for a specific systemd service.
- Check system load:
uptime/top - Identify CPU/memory hogs:
htop - Inspect logs for errors:
tail -f /var/log/syslog - Restart failing services:
sudo systemctl restart <service> - Verify service status:
sudo systemctl status <service>