How to get cpu temperature in linux

How can I monitor the CPU temperature under linux?

As others have noted, you need the lm-sensors package. I thought I should mention that in addition to installing the package, you should run the sensors-detect command to identify the kernel modules that need to be loaded.

If you haven’t done this, manually run this once and check if it detects any sensors on board your computer.

$ sudo sensors-detect # sensors-detect revision 5249 (2008-05-11 22:56:25 +0200) This program will help you determine which kernel modules you need to load to use lm_sensors most effectively. It is generally safe and recommended to accept the default answers to all questions, unless you know what you're doing. We can start with probing for (PCI) I2C or SMBus adapters. Do you want to probe now? (YES/no): Probing for PCI bus adapters. Use driver `i2c-i801' for device 0000:00:1f.3: Intel 82801G ICH7 We will now try to load each adapter module in turn. Module `i2c-i801' already loaded. If you have undetectable or unsupported I2C/SMBus adapters, you can have them scanned by manually loading the modules before running this script. We are now going to do the I2C/SMBus adapter probings. Some chips may be double detected; we choose the one with the highest confidence value in that case. If you found that the adapter hung after probing a certain address, you can specify that address to remain unprobed. Next adapter: SMBus I801 adapter at 10c0 (i2c-0) Do you want to scan it? (YES/no/selectively): Client found at address 0x50 Probing for `Analog Devices ADM1033'. No Probing for `Analog Devices ADM1034'. No Probing for `SPD EEPROM'. Yes (confidence 8, not a hardware monitoring chip) Probing for `EDID EEPROM'. No Client found at address 0x52 Probing for `Analog Devices ADM1033'. No Probing for `Analog Devices ADM1034'. No Probing for `SPD EEPROM'. Yes (confidence 8, not a hardware monitoring chip) Probing for `EDID EEPROM'. No Some chips are also accessible through the ISA I/O ports. We have to write to arbitrary I/O ports to probe them. This is usually safe though. Yes, you do have ISA I/O ports even if you do not have any ISA slots! Do you want to scan the ISA I/O ports? (YES/no): Probing for `National Semiconductor LM78' at 0x290. No Probing for `National Semiconductor LM78-J' at 0x290. No Probing for `National Semiconductor LM79' at 0x290. No Probing for `Winbond W83781D' at 0x290. No Probing for `Winbond W83782D' at 0x290. No Probing for `IPMI BMC KCS' at 0xca0. No Probing for `IPMI BMC SMIC' at 0xca8. No Some Super I/O chips may also contain sensors. We have to write to standard I/O ports to probe them. This is usually safe. Do you want to scan for Super I/O sensors? (YES/no): Probing for Super-I/O at 0x2e/0x2f Trying family `National Semiconductor'. No Trying family `SMSC'. Yes Found unknown chip with ID 0x2803 Probing for Super-I/O at 0x4e/0x4f Trying family `National Semiconductor'. No Trying family `SMSC'. No Trying family `VIA/Winbond/Fintek'. No Trying family `ITE'. No Some south bridges, CPUs or memory controllers may also contain embedded sensors. Do you want to scan for them? (YES/no): Silicon Integrated Systems SIS5595. No VIA VT82C686 Integrated Sensors. No VIA VT8231 Integrated Sensors. No AMD K8 thermal sensors. No AMD K10 thermal sensors. No Intel Core family thermal sensor. Success! (driver `coretemp') Intel AMB FB-DIMM thermal sensor. No Now follows a summary of the probes I have just done. Just press ENTER to continue: Driver `coretemp' (should be inserted): Detects correctly: * Chip `Intel Core family thermal sensor' (confidence: 9) I will now generate the commands needed to load the required modules. Just press ENTER to continue: To load everything that is needed, add this to /etc/modules: #----cut here---- # Chip drivers coretemp #----cut here---- Do you want to add these lines automatically? (yes/NO) 

If you’re lucky, your laptop will support an array of sensors. If not, you may still find a basic set of sensors for the CPU:

$ sensors acpitz-virtual-0 Adapter: Virtual device temp1: +40.5°C (crit = +105.0°C) coretemp-isa-0000 Adapter: ISA adapter Core 0: +35.0°C (crit = +100.0°C) coretemp-isa-0001 Adapter: ISA adapter Core 1: +40.0°C (crit = +100.0°C) 

Источник

Читайте также:  Installing raspbian from linux

Find Out CPU Temperature From the Command-Line

announcement - icon

The Kubernetes ecosystem is huge and quite complex, so it’s easy to forget about costs when trying out all of the exciting tools.

To avoid overspending on your Kubernetes cluster, definitely have a look at the free K8s cost monitoring tool from the automation platform CAST AI. You can view your costs in real time, allocate them, calculate burn rates for projects, spot anomalies or spikes, and get insightful reports you can share with your team.

Connect your cluster and start monitoring your K8s costs right away:

1. Overview

In this tutorial, we’ll take a look at how we can check for the CPU temperature on the Linux terminal. First, we’ll see how we can figure out the temperature of our CPUs without the help of third-party tools. Afterward, we’ll cover a couple of small useful utilities for the same purpose.

2. Finding CPU Temperature Without Third-Party Tools

On Linux, we can read almost every accessible detail related to hardware resources. These details include the count of the CPU cycles, CPU temperature, I/O usage, network usage, and more. This is all possible because Linux gives us more control over the hardware and software.

2.1. The /sys/class Directory

The /sys directory is a virtual file system that contains a plethora of information regarding the Linux kernel and the hardware. The files inside this directory don’t actually reside on the disk. Instead, they’re only created and updated on-the-fly as we read them.

The /sys/class directory is the hierarchy of the hardware. This directory mostly contains information about the devices that are registered with the kernel.

Читайте также:  Linux проверить пинг до сервера

One of the directories is called thermal, which contains temperature information of the hardware resources:

$ ls -lL /sys/class/thermal total 0 . drwxr-xr-x 3 root root 0 Apr 7 00:05 cooling_device7 drwxr-xr-x 3 root root 0 Apr 7 00:05 cooling_device8 drwxr-xr-x 4 root root 0 Apr 7 00:05 thermal_zone0 drwxr-xr-x 3 root root 0 Apr 7 00:05 thermal_zone1 drwxr-xr-x 3 root root 0 Apr 7 00:05 thermal_zone2

In this directory, we’re concerned with the thermal_zone directories. The thermal_zone directories correspond to the thermometers placed on our motherboard.

Let’s cd into the thermal_zone0 directory and check what it contains:

$ cd thermal_zone0 && ls -lL total 0 . drwxr-xr-x 2 root root 0 Apr 7 00:05 subsystem -rw-r--r-- 1 root root 4096 Apr 7 00:55 sustainable_power -r--r--r-- 1 root root 4096 Apr 7 00:29 temp -r--r--r-- 1 root root 4096 Apr 7 00:29 type -r--r--r-- 1 root root 4096 Apr 7 00:29 trip_point_0_temp . 

As we can see, it includes lots of files and directories. However, we’re only interested in the temp and the type files.

2.2. The temp File

The temp file contains the actual temperature of the zone. It should contain just a single integer value:

We can divide this value by 100 to get the actual temperature in Celsius. In this case, it would be 27.8 °C.

2.3. The type File

The type file contains a value that signifies the zone to which the temperature corresponds:

The acpitz thermometer is located beside the CPU socket. However, we are interested in the CPU temperature. Similarly, for the CPUs, we can check the other thermal_zone directories that might contain this thermal information.

2.4. Putting It All Together

It can be tedious to check for CPU temperature this way because these directories might be different on different machines. Interestingly, the zone information is defined in the driver for the hardware resources.

Читайте также:  Linux edit system files

For that reason, we might want to use a command that prints out this information in a readable way:

  • We read the type and file files from each thermal_zone directory and feed the result to paste
  • The paste command will align the lines from the corresponding files, separated by tabs
  • We pipe the output of the paste command to column, which further aligns the output into columns
  • The contents of column are then piped to sed, which replaces the values with readable temperature values

Additionally, we can create a simple shell script out of this rather long command and execute it either directly or from another script.

3. Alternative: lm_sensors

lm_sensors is a handy utility for monitoring temperatures, voltage, fan speed, and other hardware sensor information.

3.1. Installation

On major Linux distributions, lm_sensors should already be installed. However, if it’s not, we can use a package manager to install it from our distro’s official package repository:

# Ubuntu-like $ apt install lm-sensors
# Fedora, RHEL, openSUSE $ yum install lm_sensors
# Arch-like $ pacman -S lm_sensors

Once installed, let’s verify it:

$ sensors -v sensors version 3.6.0+git with libsensors version 3.6.0+git

3.2. Usage

We can use lm_sensors by simply typing in the sensors command:

$ sensors acpitz-acpi-0 Adapter: ACPI interface temp1: +27.8 C temp2: +29.8 C coretemp-isa-0000 Adapter: ISA adapter Package id 0: +40.0 C Core 0: +39.0 C Core 1: +40.0 C

As we can see, the CPU temperature for each core is given in the Core 0 and Core 1 fields, respectively.

Moreover, if it doesn’t display the CPU temperature, we can run the sensors-detect command beforehand. The sensors-detect command will detect all the available sensors attached to the machine.

4. Alternative: acpi

acpi is another lightweight alternative that we can use to display the temperature and battery information.

4.1. Installation

The acpi utility doesn’t ship with most distributions, so we’ll have to install it from our official package repository using the package name acpi:

# Ubuntu-like $ apt install acpi
# Fedora, RHEL, openSUSE $ yum install acpi

After the installation, let’s verify it:

4.2. Usage

We can print out the temperature information with acpi by simply running it with the -t or –thermal option:

$ acpi -t Thermal 0: ok, 29.8 degrees C Thermal 1: ok, 27.8 degrees C

We can print a detailed report with the -i or –details option as well.

5. Conclusion

In this article, we covered how we can check the thermal status of our CPUs. First, we experimented with the raw thermal details provided by the Kernel in the /sys/class directory. Afterward, we used a couple of alternative tools that automate this process for us.

Источник

Оцените статью
Adblock
detector