monitor cpu ubuntu

High CPU usage can lead to degraded system performance and even crashes in the worst cases. The first step to fixing this issue is checking the CPU utilization to identify which processes are actually eating up the resources.

If you’ve got a high-end rig, monitoring the CPU temperature during intensive tasks like gaming or editing is also important for the system’s long-term health. We’ll explain how you can get all such CPU stats on Ubuntu in this article.

System Monitor

All Ubuntu flavors have some type of system monitor preinstalled. Standard Ubuntu installations ship with the GNOME System Monitor while Kubuntu uses KSysGuard. Similarly, other flavors have their own versions like LXTask, MATE System Monitor, and Task Manager.

For new users, these utilities will be the easiest way to monitor the CPU. Search ‘monitor’ and open the relevant System Monitor. I’ll show the GNOME System Monitor for reference here.

In the Processes tab, you can sort by CPU Usage % to find which processes are currently taking the most CPU resources.

In the Resources tab, you can check the overall CPU usage as well as the utilization stats for individual threads.

Keep in mind that this tool is intended for beginners, so you won’t have access to advanced stats. For that, you have plenty of other options as we’ve shown further in this article.

Htop

While there are a lot of good CLI monitors on Linux, Htop is likely the most popular one. It’s a powerful utility that you can use to both monitor and manage processes.

There are simpler versions like top, and other powerful alternatives like atop, btop, gtop, gotop, etc. But we’ll focus on Htop here as we feel it gives just the right amount of data for most users. 

You can install and launch htop with the following commands.

sudo apt install htop
htop

The CPU threads with usage percentages are listed at the top. The colored bars mean:

  • Green (User processes)
  • Red (Kernel processes)
  • Aqua blue (Virtualized processes)
  • Blue (Low-priority threads).

At the lower end, you’ll find the CPU usage % of each process. You can press F6 and select PERCENT_CPU to sort the processes by CPU usage %.

You can also go to Setup (F2) > Display Options and choose to display advanced stats like CPU time, frequency, and temperature. 

Do note that the last one will only work if you compiled htop from source with the --enable-sensors build option. With this feature, htop can use the libsensors library to read and display temperature data.

Glances

Glances is a system monitor that displays advanced CPU info as well as temperature stats by default. Unlike most monitoring apps, Glances is not lightweight, but there’s a good reason for this. It supports various useful features including remote monitoring via a web or CLI interface.

To explore such features, install and launch Glances with the following commands.

sudo apt install glances
glances

First of all, the temperature data is shown in the sensors section at the bottom left. The sensors listed here will differ but some common ones related to the CPU include:

  • acpitz (located near CPU socket)
  • x86_pkg_temp (embedded in the CPU)
  • Tdie (temperature of the CPU die)
  • Tctl (hotspot temp, i.e., the highest temp among all the sensors)

At the top, you get some in-depth CPU usage stats. You can press c to sort the processes by CPU% and 1 to switch between summary and per-CPU views.

In terms of the actual data, the CPU-related fields are as follows:

  • CPU: Overall CPU usage
  • user: % time spent running userspace code
  • system: % time spent running kernel space code
  • iowait: % time spent waiting for I/O operations to complete 
  • idle: Currently unused processing capacity
  • irq: % time spent servicing hardware or software interrupts
  • nice: % time taken by user processes with a +ve nice value
  • steal: % time for which the VM process has waited for the hypervisor to allocate a physical CPU.
  • ctx_sw: total context switches per second (voluntary and involuntary)
  • inter: interrupts per second
  • sw_int: software interrupts per second

If you want to set up remote monitoring with Glances, you must open the appropriate port on the server firewall first (default – 61209).

sudo ufw allow 61209
sudo ufw reload 

Then you can run Glances with CLI access.

glances -s

Now from the client machine, you can connect to the server by specifying the IP address like so.

glances -c @192.168.10.169

You can also start Glances as a web server.

glances -w

This’ll allow you to monitor your system from a web browser (both on server and client systems). Just remember to change the IP address (and port if required) when entering it in the URL bar.

https://192.168.10.169:61209

Lm_sensors and Frontends

The Linux monitoring sensors (lm_sensors) package provides drivers and various tools for monitoring temperature and related data on Linux. It supports a variety of frontends for displaying sensor data.

Most notably, there’s Netdata. It’s similar to Glances (web-based monitoring and access to in-depth data) while also being lightweight. We won’t talk about Netdata in detail here as we’ve already covered Glances, but it’s definitely a great tool worth checking out.

psensor is another good GTK app mainly used for monitoring hardware temperature stats (CPU, motherboard, GPU, etc.). You can integrate it with your DE to display the stats directly on the desktop menu which is pretty handy.

There are a lot of other graphical frontends, but regardless of which you decide to use, you’ll need to install lm-sensors first.

sudo apt install lm-sensors

To check which hardware sensors you have and load the necessary kernel modules, run

sudo sensors-detect --auto
/etc/init.d/kmod start

Now, you can check the stats with

sensors

The data here is fine, but we’re actually looking for desktop integration to monitor these stats conveniently. So, we’ll install Psensor.

sudo apt install psensor

Launch psensor and select Psensor > Sensor Preferences. 

Select the appropriate sensor/metric, switch to the Application Indicator tab, and enable the Display sensor in the label option.

You should be able to monitor the CPU usage and/or temperature stats directly from the top bar now.

Anup Thapa

Senior Writer

Anup Thapa is a Linux enthusiast with an extensive background in computer hardware and networking. His goal is to effectively communicate technical concepts in a simplified form understandable by new Linux users. To this end, he mainly writes beginner-friendly tutorials and troubleshooting guides. Outside of work, he enjoys reading up on a range of topics, traveling, working out, and MOBAs.