Overview
The temperature functions retrieve readings from hardware temperature sensors including CPU, GPU, storage devices, and other components. This is essential for thermal monitoring and system health management.Functions
Parameters
Context for cancellation and timeout control
Returns
Returns a slice ofTemperatureStat structures containing temperature data from all available sensors.
TemperatureStat Structure
TheTemperatureStat struct represents a single temperature sensor reading.
Fields
Unique identifier for the temperature sensor. Format varies by platform and sensor type.Examples:
"coretemp_core_0"- Intel CPU core 0"coretemp_core_1"- Intel CPU core 1"k10temp_tctl"- AMD Ryzen Tctl temperature"nvme_composite"- NVMe SSD composite temperature"acpitz"- ACPI thermal zone"iwlwifi_1"- Intel wireless adapter
Current temperature reading in degrees Celsius.
High temperature threshold in degrees Celsius. System may issue warnings or begin throttling when this temperature is reached. Returns
0 if threshold is not available or not supported by the sensor.Critical temperature threshold in degrees Celsius. System may shut down to prevent hardware damage when this temperature is exceeded. Returns
0 if threshold is not available or not supported by the sensor.Platform Support
Linux
Full support with multiple data sources
Full support with multiple data sources
Linux provides the most comprehensive temperature monitoring through:Primary: hwmon interface
- Location:
/sys/class/hwmon/hwmon*/temp*_input - Alternative:
/sys/class/hwmon/hwmon*/device/temp*_input(CentOS) - Provides current temperature, high threshold, and critical threshold
- Sensor names from
temp*_labelfiles - Temperatures in millidegrees Celsius (divided by 1000)
- Location:
/sys/class/thermal/thermal_zone*/ - Used on systems without hwmon (e.g., Raspberry Pi)
- Reads from
tempandtypefiles - Limited threshold information
macOS (Darwin)
Limited platform-specific support
Limited platform-specific support
Temperature sensor access on macOS is limited:
- Requires SMC (System Management Controller) access
- May require additional permissions or tools
- Sensor availability depends on hardware model
- Often requires third-party libraries for full functionality
Windows
Requires WMI or driver support
Requires WMI or driver support
Temperature monitoring on Windows:
- May use WMI (Windows Management Instrumentation)
- Often requires vendor-specific drivers
- Limited standardization across hardware
- Some sensors may not be accessible
BSD (FreeBSD, OpenBSD)
Platform-specific implementations
Platform-specific implementations
BSD systems have varying levels of support:
- Depends on kernel sensor framework
- May require specific kernel modules
- Sensor access varies by hardware
Sensor Types and Naming
CPU Sensors
Intel Core processors report per-core temperatures:
coretemp_core_0,coretemp_core_1, etc.coretemp_package_id_0for overall package temperature
AMD Ryzen and EPYC processors:
k10temp_tctl- Control temperaturek10temp_tdie- Die temperaturek10temp_tccd1,k10temp_tccd2- CCD temperatures
Storage Sensors
NVMe drives report multiple temperatures:
nvme_composite- Overall drive temperaturenvme_sensor_1,nvme_sensor_2- Individual sensors
Traditional hard drives and SSDs:
drivetempfollowed by device identifier
GPU Sensors
GPU temperatures:
nouveaufor NVIDIA with open-source driveramdgpufor AMD graphicsradeonfor older AMD cards
Other Sensors
Generic motherboard thermal zones managed by ACPI.
Intel wireless network adapter temperatures.
Chipset temperatures on Intel platforms.
Usage Examples
Basic Temperature Reading
Display with Thresholds
CPU Temperature Monitoring
Temperature Alert System
Continuous Temperature Monitoring
Export to JSON
Filter by Temperature Range
Using Context with Timeout
Performance Considerations
- Reading temperatures is relatively lightweight
- Safe to poll every few seconds
- File I/O is cached by the kernel
- Minimal CPU overhead
Error Handling
Troubleshooting
No sensors found
No sensors found
- Check if running in a virtual machine (sensors often not available)
- Ensure proper kernel modules are loaded (
lm-sensorson Linux) - Verify system has physical temperature sensors
- Check permissions (some systems may require elevated privileges)
Zero or missing thresholds
Zero or missing thresholds
- Not all sensors provide threshold information
HighandCriticalfields will be 0 when unavailable- This is normal behavior and should be handled in your code
Incorrect readings
Incorrect readings
- Some sensors may require calibration
- Verify sensor drivers are up to date
- Compare with other monitoring tools
- Some readings may be in different units (check documentation)
Common Use Cases
- Server thermal monitoring and alerting
- Overclocking safety monitoring
- Datacenter environmental tracking
- Hardware diagnostics and troubleshooting
- Performance tuning (identifying thermal throttling)
- Cooling system effectiveness validation
- Long-term hardware health tracking
See Also
- Sensors Overview - Package overview
- CPU Package - CPU utilization metrics
- Host Package - System information