Linuxstar
Published on

linux acpi: Show cooling device information

Jonas

Jonas

2 min read

The Linux ACPI (Advanced Configuration and Power Interface) provides a wealth of information about various aspects of a computer's hardware and power management. One particularly useful feature is the ability to retrieve detailed information about cooling devices. This information can be crucial for monitoring and managing the temperature of your system, especially in high-performance situations.

To access the cooling device information, you can use the sysfs virtual filesystem provided by the Linux kernel. The cooling device information can be found under the /sys/class/thermal/cooling_deviceX directory (where X is a number corresponding to each cooling device).

Here's an example of how you can retrieve and display the cooling device information using a simple Python script:

import os

def show_cooling_device_info(cooling_device):
    path = f"/sys/class/thermal/{cooling_device}"

    if not os.path.exists(path):
        print(f"Could not find cooling device {cooling_device}.")
        return

    with open(os.path.join(path, "type")) as f:
        device_type = f.read().strip()
        print(f"Device Type: {device_type}")

    with open(os.path.join(path, "cur_state")) as f:
        cur_state = f.read().strip()
        print(f"Current State: {cur_state}")

    with open(os.path.join(path, "max_state")) as f:
        max_state = f.read().strip()
        print(f"Max State: {max_state}")

    with open(os.path.join(path, "cooling_capacity")) as f:
        cooling_capacity = f.read().strip()
        print(f"Cooling Capacity: {cooling_capacity} units")

# Example usage:
show_cooling_device_info("cooling_device0")

In this example, the show_cooling_device_info function takes a cooling device identifier as a parameter. The function first checks if the specified cooling device exists in the /sys/class/thermal directory. If it does, it then reads and displays various properties of the cooling device, such as its type, current state, maximum state, and cooling capacity.

By running this script, you can retrieve and display the cooling device information for a specific device. This information can be useful for monitoring the performance and temperature of your system, especially in resource-intensive scenarios.

It's worth noting that the available cooling devices and their properties may vary depending on your system's hardware and configuration. Therefore, it's important to adapt the script and its output to match your specific needs and environment.

In conclusion, the Linux ACPI provides a convenient way to retrieve and monitor cooling device information. By leveraging the sysfs virtual filesystem and accessing the relevant files under the /sys/class/thermal directory, you can gather valuable insights into the cooling capabilities of your system. This information can be particularly useful for system administrators, power users, and enthusiasts who want to keep a close eye on their system's temperature and performance.