How to Monitor CPU Temperature on Ubuntu: Glances, lm-sensors, and Thermal Zones Explained

1. Introduction

Monitoring CPU temperature in Ubuntu is essential for maintaining system performance and preventing potential damage caused by overheating. This becomes especially important during long periods of high workload or in high ambient temperatures. By keeping track of CPU temperature, you can ensure system stability and prevent hardware failures. In this article, we introduce several methods to check CPU temperature in Ubuntu and help you choose the best tool for your needs.

2. The Importance of Monitoring CPU Temperature in Ubuntu

Monitoring CPU temperature directly affects system performance and lifespan. Overheating can trigger thermal throttling, which automatically reduces the CPU clock speed and results in performance degradation. Furthermore, extended exposure to high temperatures can cause physical damage to the CPU and other hardware components. To avoid these issues and ensure smooth system operation, regular CPU temperature monitoring is crucial.

3. Comprehensive System Monitoring with Glances

Glances is a powerful tool that allows real-time monitoring of various system metrics, including CPU temperature. Since it provides an overview of the entire system at a glance, you can easily access details such as memory usage, disk I/O, and more—not just CPU temperature.

Installation and Setup

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

Using Web Server Mode

Glances can also run in web server mode, enabling you to monitor system information from another device via a web browser. To use this mode, run the following command:

bash glances -w

Access the provided URL from your web browser to view system metrics, including CPU temperature.

Advantages and Limitations

The greatest advantage of Glances is that it provides a comprehensive view of system information at once. However, if your goal is solely to check CPU temperature, the amount of data may feel overwhelming.

4. Using lm-sensors to Retrieve Sensor Information Directly

lm-sensors is a simple tool that retrieves sensor information directly, including CPU temperature. It is one of the most direct methods used by many Linux users to display system sensor data.

Installation and Configuration

  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 using the command: bash sudo sensors-detect
  3. Answer “YES” to the prompts to allow sensor detection.

Displaying CPU Temperature

Once detection is complete, use the sensors command to display CPU temperature along with other sensor information:

bash sensors

Running this command will show the current CPU temperature and related sensor data.

Advantages and Limitations

lm-sensors is simple, fast, and ideal for users who want to quickly check CPU temperature. However, if you need detailed system information or remote monitoring, tools like Glances may be a better fit.

5. Accessing Thermal Zone Information Directly

Ubuntu allows you to retrieve temperature data directly through the file system. This is one of the simplest methods, requiring no additional software installation.

Using /sys/class/thermal/

Temperature sensor information is stored in the /sys/class/thermal/ directory. To check CPU temperature, run the following command:

bash cat /sys/class/thermal/thermal_zone0/temp

The output is given in millidegrees. For example, 27800 means 27.8°C.

Exploring Sensors

Depending on your system, multiple sensors may exist. To check each sensor’s value, explore the thermal_zone* directories:

bash cat /sys/class/thermal/thermal_zone1/temp

Advantages and Limitations

This method requires no additional software and is very lightweight. However, sensor location and naming differ by system, which can make exploration time-consuming. Also, since values are displayed in millidegrees, careful interpretation is necessary.

6. Comparing Each Method

Each tool and method offers distinct benefits. Glances enables comprehensive system monitoring and remote access, though the amount of data can be overwhelming. lm-sensors provides a simple and direct way to check CPU temperature, making it user-friendly. Accessing system files directly requires no installation but may be less intuitive due to sensor variations and unit format.

7. Conclusion

CPU temperature monitoring is critical for preserving performance and system longevity in Ubuntu. This article introduced three methods: Glances, lm-sensors, and direct file access. Each approach is suitable for different needs, so choose the method that best fits your environment.

8. Additional Tips and Troubleshooting

  • Common Issues: If sensor information does not appear, your sensors may not be recognized. Try running sensors-detect again.
  • Advanced Usage: To automate temperature monitoring, incorporate these commands into scripts to perform periodic checks or send alerts when abnormal temperatures are detected.
年収訴求