wered
Posts: 6
Joined: Tue Sep 10, 2013 6:29 pm

Monitoring CPU/GPU Temp in real time

Mon Mar 21, 2016 1:53 am

I have the following script to check CPU/GPU temperatures, However i would like to make this script show the temperatures and update every second, and show on the same line, I have tried a few things but have not had much success. Would anyone be able to tell me how i would go about doing that?

#!/bin/bash
cpuTemp0=$(cat /sys/class/thermal/thermal_zone0/temp)
cpuTemp1=$(($cpuTemp0/1000))
cpuTemp2=$(($cpuTemp0/100))
cpuTempM=$(($cpuTemp2 %$cpuTemp1))
echo CPU temp"="$cpuTemp1"."$cpuTempM"'C"
echo GPU $(/opt/vc/bin/vcgencmd measure_temp)

Nickcn
Posts: 200
Joined: Sat Mar 05, 2016 8:18 pm
Location: USA

Re: Monitoring CPU/GPU Temp in real time

Mon Mar 21, 2016 1:57 am

deleted
Last edited by Nickcn on Mon May 16, 2016 3:39 am, edited 1 time in total.

wered
Posts: 6
Joined: Tue Sep 10, 2013 6:29 pm

Re: Monitoring CPU/GPU Temp in real time

Mon Mar 21, 2016 2:12 am

Im running it without a GUI so unfortunately that wont work, I tried somthing similar to that but when run it shows what i have pasted below. I would like it to basically overwrite the last output so it stays on one line.

frequency(45)=600000000
temp=21.3'C
frequency(45)=600000000
temp=21.3'C
frequency(45)=600000000
temp=20.7'C
frequency(45)=600000000
temp=21.3'C
frequency(45)=600000000

Nickcn
Posts: 200
Joined: Sat Mar 05, 2016 8:18 pm
Location: USA

Re: Monitoring CPU/GPU Temp in real time

Mon Mar 21, 2016 2:16 am

deleted
Last edited by Nickcn on Mon May 16, 2016 3:39 am, edited 1 time in total.

Nickcn
Posts: 200
Joined: Sat Mar 05, 2016 8:18 pm
Location: USA

Re: Monitoring CPU/GPU Temp in real time

Mon Mar 21, 2016 2:22 am

deleted
Last edited by Nickcn on Mon May 16, 2016 3:39 am, edited 1 time in total.

User avatar
rpdom
Posts: 12863
Joined: Sun May 06, 2012 5:17 am
Location: Ankh-Morpork

Re: Monitoring CPU/GPU Temp in real time

Mon Mar 21, 2016 10:17 am

Try something like this

Code: Select all

#!/bin/bash

while true
do
  cpuTemp0=$(cat /sys/class/thermal/thermal_zone0/temp)
  cpuTemp1=$(($cpuTemp0/1000))
  cpuTemp2=$(($cpuTemp0/100))
  cpuTempM=$(($cpuTemp2 %$cpuTemp1))
  clear
  echo "CPU temp=$cpuTemp1.$cpuTempM'C"
  echo "GPU $(/opt/vc/bin/vcgencmd measure_temp)"
  sleep 1
done

zealousd
Posts: 93
Joined: Sun Mar 20, 2016 10:57 am

Re: Monitoring CPU/GPU Temp in real time

Mon Mar 21, 2016 10:24 am

is there an easy way to log the data like every 60s record data to log

also nice log my pi is running at 27c (better then my tower lol)
Raspberry Pi 3
Ubuntu Mate
Web Server

User avatar
startrek.steve
Posts: 372
Joined: Thu Aug 30, 2012 7:19 pm

Re: Monitoring CPU/GPU Temp in real time

Mon Mar 21, 2016 11:39 am

zealousd wrote:is there an easy way to log the data like every 60s record data to log

also nice log my pi is running at 27c (better then my tower lol)

This?
in Cron
* * * * * /home/pi/job.sh
Pi 2 running LibreElec Krypton, Pi 2 running Wheezy Desktop, Pi 1 headless Wheezy, downloading Radio, Pi 1 running Picore headless Media Server, Pi Zero to be an Old Time Radio Project. Pi 3 testing. Pi Zero W downloading Radio shows headless.

User avatar
Ferdinand
Posts: 236
Joined: Sun Dec 01, 2013 2:24 pm
Location: Leiderdorp, NL

Re: Monitoring CPU/GPU Temp in real time

Mon Mar 21, 2016 2:05 pm

Hi wered,
I modified your script.

Code: Select all

#!/bin/bash
cpuTemp0=$(cat /sys/class/thermal/thermal_zone0/temp)
cpuTemp1=$(($cpuTemp0/1000))
cpuTemp2=$(($cpuTemp0/100))
cpuTempM=$(($cpuTemp2 % $cpuTemp1))
GPU=`/opt/vc/bin/vcgencmd measure_temp`
echo CPU temp "=" $cpuTemp1"."$cpuTempM"'C   ---  " GPU $GPU 
Then use the watch command like this:
<your working directory> watch -n 1 <your scriptname>
Success with your project!
Ferdinand

User avatar
DougieLawson
Posts: 34115
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: Monitoring CPU/GPU Temp in real time

Mon Mar 21, 2016 5:06 pm

What's the point? What does collecting those data do for you? So, your RPi is busy, it's running hot, so what?
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

2012-18: 1B*5, 2B*2, B+, A+, Z, ZW, 3Bs*3, 3B+

Any DMs sent on Twitter will be answered next month.


JovianPyx
Posts: 49
Joined: Fri Nov 20, 2015 9:34 pm

Re: Monitoring CPU/GPU Temp in real time

Sat Aug 20, 2016 11:56 pm

Does anyone know the precision of the temperature readings?

I monitor the temperature on two RPi3 boards and under equal load the CPU temperature is 4 to 5 degrees C different.

Is this difference to be expected?

One reason I'd like to know is that most of my own programs (music synthesizer) pretty much burn 3 cores and I'd like to know that the temperature reading is accurate, I prefer not to get past 80C.

User avatar
DougieLawson
Posts: 34115
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: Monitoring CPU/GPU Temp in real time

Sun Aug 21, 2016 12:07 pm

You get precision 5 and scale 3.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

2012-18: 1B*5, 2B*2, B+, A+, Z, ZW, 3Bs*3, 3B+

Any DMs sent on Twitter will be answered next month.

talker1
Posts: 4
Joined: Wed Jan 20, 2016 7:05 pm

Re: Monitoring CPU/GPU Temp in real time

Mon Jan 16, 2017 6:49 am

Monitoring temperature in real time.
In raspbian jessie with pixel, right click on a free task bar spot, Add/Remove Panel Items, already in Panel Applets, add Temperature Monitor.

casperl
Posts: 2
Joined: Sat Nov 25, 2017 10:19 pm

Re: Monitoring CPU/GPU Temp in real time

Wed Nov 29, 2017 1:56 pm

DougieLawson wrote:
Mon Mar 21, 2016 5:06 pm
What's the point? What does collecting those data do for you? So, your RPi is busy, it's running hot, so what?
Yes, I am replying to a dated post, but collecting temperature data is critical in my case. I have built a portable wooden box containing a small screen, Pi 3, 500Gb (2TB is possible) powered USB drive and speakers. The purpose is as a video jukebox, primarly to play podcast-style videos in .3gp format sourced from Youtube playlists using youtube-dl. Many podcasters now do Youtube and no longer mp3 files, the low VHS class quality and small file size of .3gp is perfect for this use case. It also works brilliantly as a 1960/70's classic rock video jukebox and causes quite a stir whenever I demonstrate it.

The one and only snag in this project (other than having three different power supplies to build into the box) is temperature. Though I did my homework, I never saw the temperature issue coming. The Pi temperature rises within minutes from 45 deg C to redline at >90% for all four cores and > 80 deg C. A compounding effect is that the daily summer temperature in South Africa is > 30 deg C.

So I have to use heatsinks and fans, external facing aluminum plates or large audio-style heatsinks, tweaking internal airflow and whatever else to cool my project. It is also critical now to log the temperature to evaluate which modification is the most effective and to evaluate whether this project can be achieved using the RPI3.

A side issue is that while the Pi3 might have a four core CPU, utilising that power will remain a unrealised dream, unless active cooling is employed.

User avatar
DougieLawson
Posts: 34115
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: Monitoring CPU/GPU Temp in real time

Thu Nov 30, 2017 7:24 am

Once you've done those experiments and determined that a heatsink is what you need then, as usual, there will be zero value monitoring CPU temp as there'll be nothing more you can do to cool the system.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

2012-18: 1B*5, 2B*2, B+, A+, Z, ZW, 3Bs*3, 3B+

Any DMs sent on Twitter will be answered next month.

ejolson
Posts: 2020
Joined: Tue Mar 18, 2014 11:47 am

Re: Monitoring CPU/GPU Temp in real time

Sat Dec 02, 2017 6:57 am

casperl wrote:
Wed Nov 29, 2017 1:56 pm
DougieLawson wrote:
Mon Mar 21, 2016 5:06 pm
What's the point? What does collecting those data do for you? So, your RPi is busy, it's running hot, so what?
Yes, I am replying to a dated post, but collecting temperature data is critical in my case. I have built a portable wooden box containing a small screen, Pi 3, 500Gb (2TB is possible) powered USB drive and speakers. The purpose is as a video jukebox, primarly to play podcast-style videos in .3gp format sourced from Youtube playlists using youtube-dl. Many podcasters now do Youtube and no longer mp3 files, the low VHS class quality and small file size of .3gp is perfect for this use case. It also works brilliantly as a 1960/70's classic rock video jukebox and causes quite a stir whenever I demonstrate it.

The one and only snag in this project (other than having three different power supplies to build into the box) is temperature. Though I did my homework, I never saw the temperature issue coming. The Pi temperature rises within minutes from 45 deg C to redline at >90% for all four cores and > 80 deg C. A compounding effect is that the daily summer temperature in South Africa is > 30 deg C.

So I have to use heatsinks and fans, external facing aluminum plates or large audio-style heatsinks, tweaking internal airflow and whatever else to cool my project. It is also critical now to log the temperature to evaluate which modification is the most effective and to evaluate whether this project can be achieved using the RPI3.

A side issue is that while the Pi3 might have a four core CPU, utilising that power will remain a unrealised dream, unless active cooling is employed.
Since everything is enclosed in a wooden box you will probably want some airflow through the box, if not for the Raspberry Pi then for the power supplies and amplifier driving the speakers. While some of the scripts for monitoring temperature have been deleted from this thread, there is enough remaining to get data to tune your design.

My guess is a fan to pull air out the back and a larger-than-tiny heatsink on the Pi should be sufficient and also the cheapest. Extending a large block of aluminium through the side of the wooden case that is in direct contact inside with the CPU on the Pi may be sufficient to cool the Pi and avoids objectionable fan noise, however, there may still be issues with the power supplies and other electronics you have enclosed in the box. You would need temperature measurements of all of those to know whether any cooling design is working well. Sounds like a nice jukebox podcasting device!

Return to “General programming discussion”