Identifying High CPU
Check current CPU usage:
top
htop # More user-friendly
uptime # Shows load average
Find the Culprit Process
# Show top CPU-consuming processes
ps aux --sort=-%cpu | head -10
# Real-time monitoring
top -c
htop -t # Tree view
Common High CPU Culprits
1. Web Server (Apache/Nginx)
Check for traffic spikes or misconfigurations:
sudo tail -f /var/log/nginx/access.log
sudo apache2ctl status # For Apache
Reduce worker processes:
# Nginx
sudo nano /etc/nginx/nginx.conf
# worker_processes auto; -> worker_processes 2;
2. PHP-FPM
sudo systemctl status php*-fpm
# Check pm.max_children setting
sudo nano /etc/php/*/fpm/pool.d/www.conf
3. MySQL/MariaDB
sudo mysqladmin processlist
mysql -e "SHOW FULL PROCESSLIST"
4. Cron Jobs
Check if multiple cron jobs overlap:
grep -r "*/" /etc/cron* # Find frequent jobs
sudo tail -f /var/log/syslog | grep CRON
5. Malware/Bitcoin Miners
Suspicious processes with random names:
sudo netstat -tunap | grep ESTABLISHED
sudo lsof -i
ps aux | grep -E "minerd|cpuminer|stratum"
Immediate Mitigation
# Kill problematic process (replace PID)
sudo kill -9 PID
# Renice a process (lower priority)
sudo renice +19 -p PID
# Restart the service
sudo systemctl restart servicename
Preventive Measures
- Set CPU limits with cgroups
- Implement CloudLinux or similar
- Upgrade VPS plan if consistently high
- Add monitoring (Netdata, Prometheus)