Diagnosing High CPU Usage
High CPU usage can make your server slow and unresponsive. The `top` and `htop` commands are essential for diagnosis.
Using `htop`
If not installed, run `sudo apt install htop`. Then simply run `htop`.
The output shows a list of all running processes. You can sort by CPU usage by pressing `F6` and selecting `PERCENT_CPU`. The processes at the top are your biggest consumers.
Common Culprits
- Web Servers: Apache (`apache2`) or Nginx (`nginx`) processes under heavy traffic.
- PHP Scripts: A `php-fpm` process could indicate a runaway script or plugin.
- Databases: A `mysqld` process could be handling complex, unoptimized queries.
- Malware: Unrecognized processes with high CPU usage should be investigated immediately.