How to Configure Zabbix Agent to Monitor CPU Temperature on Linux
This guide explains how to install lm_sensors, write a Bash script to retrieve CPU temperature, configure a Zabbix agent UserParameter, restart the agent, and set up a corresponding monitoring item on the Zabbix server, enabling automated CPU temperature monitoring.
Prerequisite: the monitored host must have Zabbix agent installed with the same version as the server.
1. Install lm_sensors and run sensor detection.
yum install lm_sensors -y
sensors-detect # answer yes to all prompts2. Create a shell script ( cpu.sh ) that accepts a metric argument ( cpu1 or cpu2 ) and returns the corresponding CPU temperature or 0 if unavailable.
#!/bin/bash
#by 20231214
metric=$1
case $metric in
cpu1)
cpu1=$(sensors|grep "Package id 0" |cut -c 17-20)
if [ "$cpu1" == "" ]; then
echo 0
else
echo $cpu1
fi
;;
cpu2)
cpu2=$(sensors|grep "Package id 1" |cut -c 17-20)
if [ "$cpu2" == "" ]; then
echo 0
else
echo $cpu2
fi
;;
*)
echo -e "\e[033mUsage: sh $0 [cpu1|cpu2]\e[0m"
;;
esac3. Add a UserParameter to the Zabbix agent configuration to call the script.
UserParameter=get_temp_cpu[*] /etc/zabbix/cpu.sh4. Restart the Zabbix agent service to apply the changes.
systemctl restart zabbix-agent5. On the Zabbix server, create a monitoring item using the key get_temp_cpu[cpu1] (or cpu2 ) and add it to the appropriate host template.
Practical DevOps Architecture
Hands‑on DevOps operations using Docker, K8s, Jenkins, and Ansible—empowering ops professionals to grow together through sharing, discussion, knowledge consolidation, and continuous improvement.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.