How to Easily Check CPU Temperature on Ubuntu – A Step-by-Step Guide Using Glances and lm-sensors

1. Introduction

Monitoring CPU temperature on Ubuntu is essential for maintaining system performance and preventing potential damage caused by overheating. This is especially important during prolonged high-load tasks or in environments with high ambient temperatures. In this article, we will introduce various methods to check CPU temperature on Ubuntu and help you choose the right tool based on your needs.

2. Importance of Monitoring CPU Temperature on Ubuntu

Monitoring CPU temperature directly affects system performance and longevity. Overheating can trigger thermal throttling, which automatically lowers the CPU clock speed and reduces performance. Additionally, prolonged overheating may cause physical damage to the CPU and other hardware components. To prevent these issues, regular CPU temperature monitoring is crucial for ensuring stable system operation and avoiding hardware failures.

侍エンジニア塾

3. Comprehensive System Monitoring with Glances

Glances is a powerful tool that allows real-time monitoring of various system metrics, including CPU temperature. It provides an overview of the entire system, enabling you to check not only CPU temperature but also memory usage, disk I/O, and other key information at a glance.

Installation and Setup

  1. To install Glances, first use Python’s package manager, pip:
    bash sudo apt install python3-pip sudo pip3 install glances
  2. After installation, launch Glances with the following command:
    bash glances
  3. Once Glances is running, press the [f] key to display sensor information, including CPU temperature.

Using Web Server Mode

Glances can also run in web server mode, allowing you to monitor system information from other devices via a web browser. To enable this mode, run the following command:
bash glances -w
Access the provided URL in your web browser to view system information, including CPU temperature.

Advantages and Limitations

The biggest advantage of Glances is its ability to provide a detailed overview of the entire system at a glance. However, if you only need to check CPU temperature, the amount of information displayed may feel overwhelming.

4. Retrieving Sensor Data Directly with lm-sensors

lm-sensors is a simple tool that allows direct access to sensor information, including CPU temperature. It is one of the most straightforward methods for displaying sensor data and is widely used by Linux users.

Installation and Setup

  1. To install lm-sensors, run the following command:
    bash sudo apt-get install lm-sensors
  2. After installation, detect all available sensors on your system by running:
    bash sudo sensors-detect
  3. Follow the prompts and enter “YES” when asked to detect sensors.

Displaying CPU Temperature

Once the detection process is complete, you can use the sensors command to display CPU temperature and other sensor data:
bash sensors
This command will output the current CPU temperature along with other sensor information.

Advantages and Limitations

lm-sensors is simple and easy to use, making it ideal for quickly checking CPU temperature. However, if you need detailed system monitoring or remote access, tools like Glances may be more suitable.

5. Accessing Thermal Zone Information Directly

On Ubuntu, you can retrieve temperature sensor data directly through the system’s file system. This is one of the simplest methods and does not require any additional software installation.

Using /sys/class/thermal/

Temperature sensor data is stored in the /sys/class/thermal/ directory. To check the CPU temperature, run the following command:
bash cat /sys/class/thermal/thermal_zone0/temp
The output is in millidegrees Celsius, meaning a value of 27800 represents 27.8°C.

Exploring Sensors

Some systems may have multiple sensors. To check values for different sensors, explore the thermal_zone* directories:
bash cat /sys/class/thermal/thermal_zone1/temp

Advantages and Limitations

The main advantage of this method is that it does not require additional software. However, sensor names and locations may vary by system, making it difficult to find the correct file. Additionally, since the output is in millidegrees, extra caution is needed when interpreting the values.

6. Comparison of Methods

Each tool and method has its own advantages and limitations. Glances provides comprehensive system monitoring and remote access but can be overwhelming due to the amount of information displayed. On the other hand, lm-sensors offers a simple and direct way to check CPU temperature, making it easy to use. Finally, accessing system files directly requires no additional software but may be less user-friendly due to system-dependent sensor locations and millidegree outputs.

7. Conclusion

Monitoring CPU temperature is crucial for maintaining the performance and longevity of an Ubuntu system. In this article, we introduced three methods: Glances, lm-sensors, and direct access to system files. Each method has its own strengths, so choose the one that best suits your needs and environment.

8. Additional Tips and Troubleshooting

  • Common Issues: If sensor information does not appear, the sensors may not be properly recognized. Try running sensors-detect again.
  • Advanced Use: If you want to automate temperature monitoring, you can integrate these commands into a script to check regularly and send alerts if anomalies are detected.