Monitoring CPU Temperature and Fan RPM Using the sensors Command in the Proxmox Shell, Retrieving Data via the Proxmox API, and Recording it in Zabbix

ramin110

New Member
Dec 21, 2024
2
1
3
Hello everyone,

I am currently using the l-sensors command to read CPU temperature within a Proxmox environment, and I would like to monitor these values on my Zabbix server. However, I’m unsure how to use the Proxmox API to execute the sensors command, retrieve its output in JSON format, and forward it to the Zabbix server for storage and monitoring.

I have already set up Proxmox-Zabbix communication using the Zabbix template for Proxmox, including all necessary credentials and connection configurations, so this part is not an issue.

Any guidance on how to achieve this would be greatly appreciated.

Thanks in advance for your help!

Best regards,
Ramin
 
Used these section and it worked.

#!/bin/bash

# Define the Zabbix server and host
ZABBIX_SERVER="<ZABBIX_SERVER_IP>"
ZABBIX_HOST="<Proxmox_Host_Name>"

# Extract the package temperatures for both CPUs
cpu_temp_1=$(sensors | grep -E "Package id 0" | awk '{print $4}' | tr -d '+°C')
cpu_temp_2=$(sensors | grep -E "Package id 1" | awk '{print $4}' | tr -d '+°C')

# Check if we got valid temperatures for both CPUs
if [[ -z "$cpu_temp_1" || -z "$cpu_temp_2" ]]; then
echo "Error: CPU temperatures not found"
exit 1
fi

# Send each CPU temperature to Zabbix as a float
zabbix_sender -z "$ZABBIX_SERVER" -s "$ZABBIX_HOST" -k "cpu.temperature.package1" -o "$cpu_temp_1"
zabbix_sender -z "$ZABBIX_SERVER" -s "$ZABBIX_HOST" -k "cpu.temperature.package2" -o "$cpu_temp_2"





Create Zabbix Items:

  • Go to Configuration → Hosts → Items.
  • For CPU 1:
    • Name: CPU 1 Temperature (Package)
    • Key: cpu.temperature.package1
    • Type: Zabbix trapper
    • Type of information: Numeric (float)
  • For CPU 2:
    • Name: CPU 2 Temperature (Package)
    • Key: cpu.temperature.package2
    • Type: Zabbix trapper
    • Type of information: Numeric (float)



crontab -e


* * * * * /path/to/get_cpu_temperature.sh
 
  • Like
Reactions: somebodyoverthere

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!