ps aux --sort=-%cpu | head -n 10
ps aux --sort=-%cpu | head -n 10
ps aux --sort=-%cpu | head -n 10
ps aux --sort=-%mem | head -n 10
ps aux --sort=-%mem | head -n 10
ps aux --sort=-%mem | head -n 10 - a: Show processes for all users.
- u: Display user-oriented format.
- x: Show processes not attached to a terminal.
- --sort=-%cpu: Sort by CPU usage in descending order.
- head -n 10: Display only the top 10. - r: The number of runnable processes (waiting for CPU time). A consistently high number here indicates CPU contention.
- b: Processes in uninterruptible sleep (often waiting for I/O).
- swpd: Amount of virtual memory used.
- free: Amount of idle memory.
- buff: Memory used as buffers.
- cache: Memory used as cache.
- si / so: Swap in / Swap out. High values here mean the system is heavily using swap, indicating a RAM shortage.
- bi / bo: Blocks received from / sent to the block device (disk). High values can suggest I/O bottlenecks.
- us / sy / id: User CPU time, system CPU time, and idle CPU time. If us or sy are consistently high and id is low, your CPU is busy. - Check Application Logs: Application-specific logs are your best friend. Look for error messages, repeated requests, or unusual patterns.
- Review Configuration: Ensure your application's configuration is optimized. For web servers, this might involve tuning worker processes, connection limits, or caching. For databases, it could be buffer pool sizes or query optimization.
- Update and Patch: Ensure your application and its dependencies are up to date. Bugs in older versions can lead to performance issues.
- Profile the Application: For custom applications, you might need to use profiling tools specific to the programming language (e.g., pprof for Go, cProfile for Python) to find inefficient code sections. - Check Service Status: Use systemctl status <service_name> (for systemd-based systems) to see if the service is running correctly and check its logs.
- Restart the Service: A simple restart can sometimes resolve temporary glitches: sudo systemctl restart <service_name>.
- Examine Service Configuration: Review the configuration files for the service. Misconfigurations can lead to inefficient operation.
- Disable Temporarily: If you suspect a specific service is the sole cause, you can try disabling it temporarily to see if performance improves: sudo systemctl stop <service_name> and sudo systemctl disable <service_name> (to prevent it from starting on boot). - Kernel Messages: Check kernel logs for errors: dmesg.
- Systemd Journal: For systemd systems, check the journal: journalctl -xe.
- Hardware Issues: High kernel-level CPU usage can sometimes indicate underlying hardware problems, such as a faulty disk or network card.
- Driver Problems: Outdated or buggy hardware drivers can also cause kernel-level issues. - Monitor Over Time: Use vmstat or sar (System Activity Reporter) to track memory usage trends over hours or days.
- Application-Specific Tools: Many programming languages and frameworks have tools to detect memory leaks within your application code.
- Restarting is a Band-Aid: While restarting the offending application or service will temporarily free up memory, it doesn't fix the underlying leak. You need to identify and fix the code responsible.
- Consider System-Wide Monitoring: Tools like Prometheus with node_exporter can help you track memory usage trends historically, making it easier to spot gradual increases.