lm-sensors Hardware Temperature Monitoring
lm-sensors is a Linux tool that reads temperature, voltage, and fan speed data from hardware monitoring chips on your motherboard and CPU. This guide covers installing and configuring lm-sensors, detecting available sensors, setting alert thresholds, controlling fan speeds, and integrating with monitoring platforms like Prometheus.
Prerequisites
- Ubuntu 20.04/22.04 or CentOS/Rocky Linux 8+
- Root or sudo access
- Physical server with hardware monitoring chips (most servers and desktops)
- Note: lm-sensors may not work inside virtual machines (no physical hardware)
Install lm-sensors
# Ubuntu/Debian
sudo apt update && sudo apt install -y lm-sensors fancontrol
# CentOS/Rocky Linux
sudo dnf install -y lm_sensors
# Verify installation
sensors --version
Detect and Configure Sensors
# Auto-detect all hardware monitoring chips
# This command probes for sensor chips and loads appropriate kernel modules
sudo sensors-detect
# The wizard asks several questions — answer YES to all for a thorough probe
# At the end, it shows which modules to load
# Load the detected modules immediately
sudo service kmod start
# Or load them manually:
sudo modprobe coretemp # Intel CPU temperatures
sudo modprobe nct6775 # Nuvoton super I/O (common motherboard chip)
sudo modprobe it87 # ITE super I/O chip
# Make modules persistent
sudo sensors-detect --auto # Non-interactive mode, adds modules to /etc/modules
# Verify modules are loaded
lsmod | grep -E "coretemp|nct|it87|k10temp"
Read Sensor Data
# Display all sensor readings
sensors
# Example output:
# coretemp-isa-0000
# Adapter: ISA adapter
# Package id 0: +45.0°C (high = +80.0°C, crit = +100.0°C)
# Core 0: +42.0°C (high = +80.0°C, crit = +100.0°C)
# Core 1: +43.0°C
# Core 2: +41.0°C
# Core 3: +44.0°C
#
# nct6775-isa-0290
# Adapter: ISA adapter
# SYSTIN: +35.0°C
# CPUTIN: +46.0°C
# fan1: 1200 RPM
# fan2: 800 RPM
# VCORE: +1.06 V
# +12V: +12.02 V
# +5V: +5.02 V
# JSON output for scripting
sensors -j
# Fahrenheit output
sensors -f
# Watch sensors in real time
watch -n 2 sensors
# Show specific chip
sensors coretemp-isa-0000
sensors nct6775-isa-0290
Configure Sensor Labels and Limits
Customize sensor names and thresholds in the configuration file:
# Create the main configuration file
sudo tee /etc/sensors3.conf > /dev/null <<'EOF'
# System-wide sensor configuration
chip "coretemp-isa-*"
label temp1 "CPU Package"
label temp2 "CPU Core 0"
label temp3 "CPU Core 1"
label temp4 "CPU Core 2"
label temp5 "CPU Core 3"
# Set warning threshold for CPU Package temp
set temp1_max 80
set temp1_crit 95
chip "nct6775-isa-*"
label temp1 "Motherboard"
label temp2 "CPU (Mobo)"
label fan1 "CPU Fan"
label fan2 "Case Fan 1"
label fan3 "Case Fan 2"
label in0 "Vcore"
label in1 "+12V"
label in2 "+5V"
# Fan minimum speed alerts (RPM)
set fan1_min 500
set fan2_min 300
# Temperature limits for motherboard sensor
set temp1_max 55
set temp1_crit 70
EOF
# Verify the config is valid
sensors -c /etc/sensors3.conf
# Reload with new config
sensors
Per-user configuration at ~/.config/sensors3.conf overrides system config for unprivileged reads.
Fan Speed Control with fancontrol
fancontrol automatically adjusts fan speeds based on temperature:
# Run the fan control configuration wizard
# This must be done on the physical console (not SSH) to avoid disruption
sudo pwmconfig
# The wizard:
# 1. Detects PWM-capable fans
# 2. Tests each fan's controllable range
# 3. Maps fans to temperature sensors
# 4. Generates /etc/fancontrol config
# Generated config example:
# /etc/fancontrol
INTERVAL=10 # Check every 10 seconds
FCTEMPS=hwmon2/pwm1=hwmon2/temp2_input
FCFANS=hwmon2/pwm1=hwmon2/fan1_input
MINTEMP=hwmon2/pwm1=40 # Start increasing speed at 40°C
MAXTEMP=hwmon2/pwm1=70 # Maximum speed at 70°C
MINSTART=hwmon2/pwm1=150 # Minimum PWM to start fan from standstill
MINSTOP=hwmon2/pwm1=100 # PWM at minimum running speed
# Enable and start fancontrol service
sudo systemctl enable fancontrol
sudo systemctl start fancontrol
# Check service status
sudo systemctl status fancontrol
# View fancontrol logs
sudo journalctl -u fancontrol -n 50
Manual fan control (without fancontrol daemon):
# Find PWM control files
ls /sys/class/hwmon/hwmon*/pwm*
# Enable manual control for fan (0=full auto, 1=manual, 2=auto)
echo 1 | sudo tee /sys/class/hwmon/hwmon2/pwm1_enable
# Set fan speed (0=off, 255=full speed)
echo 128 | sudo tee /sys/class/hwmon/hwmon2/pwm1 # ~50% speed
# Restore automatic control
echo 2 | sudo tee /sys/class/hwmon/hwmon2/pwm1_enable
Alert Thresholds and Notifications
# Script to check temperatures and alert if thresholds exceeded
sudo tee /usr/local/bin/temp-monitor.sh > /dev/null <<'EOF'
#!/bin/bash
ALERT_EMAIL="[email protected]"
CPU_WARN=75 # Warning threshold (°C)
CPU_CRIT=90 # Critical threshold (°C)
# Get CPU package temperature
CPU_TEMP=$(sensors -j 2>/dev/null | python3 -c "
import json, sys
data = json.load(sys.stdin)
for chip, vals in data.items():
if 'coretemp' in chip or 'k10temp' in chip:
for sensor, reading in vals.items():
if 'Package' in sensor or 'Tdie' in sensor:
for k, v in reading.items():
if 'input' in k:
print(int(v))
exit()
" 2>/dev/null || echo 0)
if [ "$CPU_TEMP" -ge "$CPU_CRIT" ] 2>/dev/null; then
echo "CRITICAL: CPU temperature ${CPU_TEMP}°C exceeds ${CPU_CRIT}°C threshold!" | \
mail -s "CRITICAL: CPU Temp Alert on $(hostname)" "$ALERT_EMAIL"
elif [ "$CPU_TEMP" -ge "$CPU_WARN" ] 2>/dev/null; then
echo "WARNING: CPU temperature ${CPU_TEMP}°C exceeds ${CPU_WARN}°C threshold!" | \
mail -s "WARNING: CPU Temp Alert on $(hostname)" "$ALERT_EMAIL"
fi
EOF
sudo chmod +x /usr/local/bin/temp-monitor.sh
# Schedule via cron (every 5 minutes)
echo "*/5 * * * * root /usr/local/bin/temp-monitor.sh" | \
sudo tee /etc/cron.d/temp-monitor
Integration with Monitoring Tools
Prometheus with node_exporter:
# node_exporter automatically exposes hwmon metrics
# Install node_exporter
wget https://github.com/prometheus/node_exporter/releases/latest/download/node_exporter-*.linux-amd64.tar.gz
tar xzf node_exporter-*.tar.gz
sudo mv node_exporter-*/node_exporter /usr/local/bin/
# Start node_exporter (hwmon collector is enabled by default)
sudo systemctl enable node_exporter
sudo systemctl start node_exporter
# Metrics are available at http://localhost:9100/metrics
# Temperature metrics:
curl -s http://localhost:9100/metrics | grep "node_hwmon_temp"
# node_hwmon_temp_celsius{chip="platform_coretemp_0",sensor="temp1"} 45.0
Grafana dashboard query:
# Average CPU temperature across all cores
avg(node_hwmon_temp_celsius{sensor=~"temp.*"}) by (instance)
# Fan speeds
node_hwmon_fan_rpm{chip=~".*nct.*"}
# Alert rule: CPU above 80°C for 5 minutes
- alert: HighCPUTemperature
expr: node_hwmon_temp_celsius{sensor="temp1"} > 80
for: 5m
labels:
severity: warning
annotations:
summary: "High CPU temperature on {{ $labels.instance }}"
Check sensor values via sysfs directly:
# Sensors are exposed through sysfs
ls /sys/class/hwmon/
# Read temperature directly (value in millidegrees Celsius)
cat /sys/class/hwmon/hwmon0/temp1_input
# 45000 = 45.0°C
# Convert in bash:
TEMP_MILLI=$(cat /sys/class/hwmon/hwmon0/temp1_input)
echo "Temperature: $((TEMP_MILLI / 1000))°C"
Troubleshooting
sensors shows no output:
# Check if any modules are loaded
lsmod | grep -E "coretemp|nct|it87|k10temp|acpi"
# Run detect again and check which modules it recommends
sudo sensors-detect --auto
# Manually load common modules
sudo modprobe coretemp # Intel CPUs
sudo modprobe k10temp # AMD CPUs (Ryzen, EPYC)
sudo modprobe nct6775 # Common Nuvoton chip
Temperature readings seem wrong:
# Compare with IPMI readings if available
ipmitool sdr type Temperature
# Check BIOS-reported temps
sudo dmidecode -t temperature 2>/dev/null
# Cross-reference with turbostat (Intel CPUs)
sudo apt install linux-tools-common && sudo turbostat --show Pkg_J,Busy%,Bzy_MHz,PkgTmp
fancontrol not starting:
# Check for errors in the config
sudo fancontrol /etc/fancontrol
# fancontrol requires PWM-capable fans connected to the motherboard headers
# USB fans and fans connected via adapters won't appear
ls /sys/class/hwmon/*/pwm*
Conclusion
lm-sensors provides direct access to hardware monitoring data that's essential for maintaining server health and preventing thermal throttling or hardware damage. Combined with fancontrol for dynamic fan management and Prometheus/Grafana for long-term trending, you can proactively respond to thermal issues before they impact performance or cause hardware failures. For baremetal servers, integrating both lm-sensors and IPMI gives you redundant thermal monitoring with alerting at multiple levels.


