Monitor CPU, memory, and GPU usage across multiple Ubuntu systems using open-source tools like htop, free, and nvidia-smi. These utilities provide real-time insights into system performance, helping you identify bottlenecks and determine if hardware upgrades are necessary for your infrastructure.
Why Monitor System Resources?
Understanding resource utilization is critical for maintaining stable and efficient Linux servers. When a system becomes unresponsive, it is often due to one of three main resources being exhausted: Central Processing Unit (CPU), Random Access Memory (RAM), or Graphics Processing Unit (GPU) compute power. By tracking these metrics over time, administrators can distinguish between temporary spikes and chronic issues that require immediate attention. This proactive approach allows for better capacity planning and ensures that applications run smoothly without unexpected crashes.Monitoring CPU Usage
The CPU is the brain of your computer, handling all computational tasks. On Ubuntu, the simplest way to view current CPU activity is through the terminal commandtop or its more user-friendly cousin, htop. Running htop provides a color-coded interface that shows individual core usage, total load averages, and process priority. If you see sustained high usage on specific cores, it may indicate that a single application is monopolizing processing power. For headless servers where graphical interfaces are unavailable, the mpstat command offers detailed statistics per processor. It is also important to check if the kernel is sending tasks to isolated cores, which can affect performance scheduling as discussed in our guide on Ubuntu Kernel Sending Task to Isolated Core.
Analyzing Memory Consumption
Memory management is often the most confusing aspect of Linux monitoring because of how the kernel handles free RAM. The commandfree -h displays total, used, and available memory in human-readable format. However, "used" memory includes buffers and cache, which the kernel uses to speed up disk I/O operations. To understand what is actually consuming RAM at the process level, use ps aux --sort=-%mem | head to list the top memory-consuming processes. If you notice a specific process using significantly more memory than expected, it might be leaking memory or running inefficiently. For deeper analysis of why a process behaves differently across environments, refer to our article on Why would a process use more memory running on one OS compared to another?. Swapping occurs when physical RAM is full, leading to severe performance degradation, so keeping an eye on swap usage via swapon --show is essential.
Tracking GPU Utilization
For systems with NVIDIA GPUs, particularly those used for machine learning, video rendering, or gaming, monitoring GPU usage is vital. The primary tool for this isnvidia-smi, which stands for NVIDIA System Management Interface. Running this command without arguments provides a snapshot of GPU temperature, power draw, memory usage, and utilization percentage. If you need to see which specific processes are utilizing the GPU memory, you can append the --query-compute-apps flag. This helps identify rogue scripts or background jobs that might be holding onto VRAM, preventing other applications from running. Understanding how to view these processes is key, as detailed in our tutorial on How to View All Processes Using GPU Memory in Linux. High GPU memory usage does not always mean high compute usage; sometimes the memory is allocated but idle, which requires different troubleshooting strategies.
Automating Multi-System Monitoring
When managing a fleet of Ubuntu computers, manual checks become impractical. You can create simple bash scripts to gather data from multiple machines remotely using SSH. A basic script can loop through a list of hostnames, executehtop -b -n 1 or nvidia-smi on each node, and save the output to a central log file. Alternatively, consider using lightweight monitoring agents like Node Exporter combined with Prometheus and Grafana. These tools provide historical data and visual dashboards, allowing you to spot trends over days or weeks rather than just instant snapshots. This long-term view is crucial for identifying gradual performance declines that might indicate failing hardware components.
Identifying Upgrade Needs
Once you have collected sufficient data, you can make informed decisions about hardware upgrades. If CPU usage consistently hits 100% during peak hours, adding more CPU cores or upgrading to a faster clock-speed processor will help. If memory is constantly near capacity with heavy swapping, adding more RAM is the most effective solution. For GPU-bound workloads, if utilization is low but memory is full, you may need a GPU with larger VRAM. Conversely, if both utilization and memory are high, a more powerful GPU model is required. Regular monitoring prevents emergency purchases by allowing you to budget for upgrades during planned maintenance windows.Frequently Asked Questions
What causes high CPU usage on an Ubuntu server?
High CPU usage is typically caused by runaway processes, heavy database queries, or insufficient scaling for web traffic. Check active processes withtop and investigate any suspicious or unexpectedly busy threads.
How do I know if my system needs more RAM?
If the "available" memory column infree -h is consistently low and swap usage is high, your system is thrashing. This leads to significant slowdowns, indicating that adding physical RAM is necessary.
Can I monitor GPU usage without NVIDIA drivers installed?
No,nvidia-smi requires proprietary NVIDIA drivers to communicate with the hardware. For AMD GPUs, you would use rocm-smi or radeontop instead.
What should I do if a process is stuck using GPU memory?
You can identify the Process ID (PID) usingnvidia-smi pmon and then terminate it with the kill command. Always try to stop the application gracefully first before forcing termination.