Operations 3 min read

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.

Practical DevOps Architecture
Practical DevOps Architecture
Practical DevOps Architecture
How to Configure Zabbix Agent to Monitor CPU Temperature on Linux

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 prompts

2. 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"
  ;;
esac

3. Add a UserParameter to the Zabbix agent configuration to call the script.

UserParameter=get_temp_cpu[*] /etc/zabbix/cpu.sh

4. Restart the Zabbix agent service to apply the changes.

systemctl restart zabbix-agent

5. 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.

Operationslinuxsystem monitoringshell scriptCPU monitoringZabbix
Practical DevOps Architecture
Written by

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.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.