CPU Temperature Monitoring Script

1. Introduction

Monitoring CPU temperature is an important part of system health checks, especially for devices running in high-load or harsh environmental conditions.
This simple Python script reads the CPU temperature from the system’s thermal interface and outputs it in Celsius.

Example Use Cases:

  • Quickly check if CPU overheating could be affecting network performance
  • Gather baseline temperature metrics for performance benchmarking
  • Monitor thermal behavior during load testing

2. Overview of the Script

This Python script:

  1. Reads the raw CPU temperature value from /sys/class/thermal/thermal_zone0/temp
  2. Converts the value from millidegrees Celsius to standard Celsius
  3. Outputs the temperature in a human-readable format

Prerequisites:

  • Linux-based NetBeez agent
  • Python 3 installed
  • Access to /sys/class/thermal/thermal_zone0/temp

Expected Output:

  • The CPU temperature in Celsius, with one decimal place of precision

3. Script Code

#!/usr/bin/env python3

# Read the temperature from the system file
with open("/sys/class/thermal/thermal_zone0/temp", "r") as f:
    raw_temp = int(f.read().strip())

# Convert to Celsius
temp_c = raw_temp / 1000

# Print in the desired format
print(f"temperature={temp_c:.1f}")

4. Sample Output

temperature=47.3

5. Closing Remarks

This script offers a quick way to check CPU temperature directly from a NetBeez agent.
It can be helpful in diagnosing thermal throttling issues or identifying hardware that’s running hotter than expected.

Have ideas to extend it? You could:

  • Output both Celsius and Fahrenheit

  • Log readings over time for trend analysis

  • Trigger alerts if the temperature exceeds a threshold

Share your modifications in the comments so others can benefit.