CPU and GPU Temperature of a Raspberry PI via CLI, SNMP and Cacti
The following is a primer for setting up your Raspberry PI to use SNMP to monitor the CPU and the GPU temperature in Cacti. The instructions below cover both Raspian and Centos 7. I am assuming you are familiar with SNMP.
Raspian
Create a file named /usr/local/sbin/cputemp
#!/bin/bash cpu=$(</sys/class/thermal/thermal_zone0/temp) echo print $cpu/1000 | /usr/bin/perl echo
Create a file named /usr/local/sbin/gputemp
#!/bin/bash gpu=$(/usr/bin/vcgencmd measure_temp) echo $gpu | /usr/bin/awk -F '=' {'print $2'} | /usr/bin/awk -F "'" {'print $1'}
Set the permissions on the above files
sudo chmod 775 /usr/local/sbin/cputemp sudo chmod 775 /usr/local/sbin/gputemp
Install snmp by:
sudo apt-get update sudo apt-get install snmpd
edit the file /etc/snmp/snmpd.conf file and add the following lines to the end
extend cputemp /usr/local/sbin/cputemp extend gputemp /usr/local/sbin/gputemp view systemonly included .1.3.6.1.4.1.8072.1.3.2
If you want to be able to monitor the network interfaces via snmp/cacti, add the following line
view systemonly included .1.3.6.1.2.1.2
If you want to be able to monitor the storage usage and memory via snmp/cacti add the following line
view systemonly included .1.3.6.1.2.1.25.2.3.1
find the line near the top of the file that reads
agentAddress udp:127.0.0.1:161
and add a “#” in front of it. Then find the line (two lines down) that reads
#agentAddress udp:161,udp6:[::1]:16
and remove the “#” in front of it
save your changes and execute
usermod -a -G video Debian-snmp /etc/init.d/snmpd restart
Centos 7
Easy Way
su - rpm -Uvh https://yum.seei.biz/altarch/7/os/armhfp/Packages/PiSNMPTemperature-1.0.0-1.noarch.rpm
Follow the instructions provided then –
Edit /etc/snmp/snmpd.conf and set the community string – then
systemctl restart snmpd
Jump down to “Testing the snmp using net-snmp-utils” below
Manual Method
Create a file named /usr/local/sbin/cputemp
#!/bin/bash cpu=$(</sys/class/thermal/thermal_zone0/temp) echo print $cpu/1000 | /bin/perl echo
Create a file named /usr/local/sbin/gputemp
#!/bin/bash gpu=$(/usr/bin/vcgencmd measure_temp) echo $gpu | /bin/awk -F '=' {'print $2'} | /bin/awk -F "'" {'print $1'}
Execute:
yum -y install net-snmp
edit the file /etc/snmp/snmpd.conf file and add the following two lines to the end
extend cputemp /usr/local/sbin/cputemp extend gputemp /usr/local/sbin/gputemp
Scroll up the snmpd.conf file and find the lines that start with
view systemvew included.....
and add the following line:
view systemview included .1.3.6.1.4.1.8072.1.3.2
save your changes and exit your editor
execute
systemctl enable snmpd
edit ipchains to permit inbound udp traffic to port 161
firewall-cmd --zone=public --add-port=161/udp --permanent firewall-cmd --reload
Important: Restart the pi now
Testing the snmp using net-snmp-utils
replace “public” with your community string
[user@mymachine ~]$ snmpwalk -v 1 -c public my.pi.ip.address nsExtendOutLine NET-SNMP-EXTEND-MIB::nsExtendOutLine."cputemp".1 = STRING: 49.388 NET-SNMP-EXTEND-MIB::nsExtendOutLine."gputemp".1 = STRING: 49.9 [user@mymachine ~]$
Depending on your snmp configuration you may get data from other points in the snmp besides the above two
Cacti Graph Template
Download this zip file, unzip it and import it into cacti, then you can quickly graph the CPU and GPU temperatures