Measure CPU Temp and CPU Load

Hi there

I haven't had any issues so far....but I would like to know how to monitor/log/view the CPU Temperature and Load so that I can see if there's an issue developing.

I have a Raspberry Pi 3 with a heat sink that seems to keep things around 45C

I am currently using this as a means to check temp...

I'm somewhat of a noob and am just hoping there are command line things I can do, via my PuTTY session to see how things are going during a print.

I did buy a webcam that can do a compressed MJPG stream...so that should help
(Found https://discourse.octoprint.org/t/i-see-high-cpu-usage-when-mjpg-streamer-is-running/202)

Thank you!

Paul

I'm running the NavBar Temp plugin which seems to take care of one of your requirements.

And--not that this would be easy--I'm running a Conky desktop on a TFT that's attached to my Raspi 3 which automagically gives me the load on the four cores which are in it. This appears to be the underlying code which reports the CPU load of each core.

Shorter version: try uptime.

I appreciate your reply...I just installed NavBar Temp and I noticed that if you refresh the page, it disappears. So...it sort of works... :slight_smile:

The info in the nav bar does disappear occasionally but it will re-appear when the information is available again.

If you're handy, I've written some JavaScript for querying the Raspi's CPU/GPU in either F/C.

raspi-temp

I wish I was handy with code...!
You're not catching my at my finest at the moment :slight_smile:

apt-get install nmon"for performance monitorin"

1 Like

I typed that in and get a prompt...next steps? (Sorry....newbie)

oh wait...add sudo... it's in

No temps in that utility...but it does have everything else!

The underlying system command for asking the Raspi its CPU temperature (in C) is:

cat /sys/class/thermal/thermal_zone0/temp

Divide what it returns by 1000 and that's the temperature in Celsius.

Combine this with the watch command and you could query the Raspi every ten seconds to see the temperature.

sudo watch -n 10 awk '{s=$1/1000} END {print s" C"}' /sys/class/thermal/thermal_zone0/temp

That gave me an error

Could you copy/paste the error you saw?

awk: line 1: runaway regular expression /1000} ...

Interesting, the first part of that works just fine:

awk '{s=$1/1000} END {print s" C"}' /sys/class/thermal/thermal_zone0/temp

When I try to put it under the control of watch it seems to have trouble...

I guess it needs a script:

echo "cat /sys/class/thermal/thermal_zone0/temp | awk '{print \$1/1000}'" > ~/scripts/temp
chmod a+x ~/scripts/temp

In order to invoke it:

watch -n 10 ~/scripts/temp

Ctl-C when you're done watching that. Change the integer 10 to 2 if you want that every two seconds.

Ahhhh that's really neat! Thanks!

Here is a longer winded version. Paste into file, chmod as above and execute, more old school :wink:

#!/bin/bash

while : 
do
  TEMP=`cat  /sys/class/thermal/thermal_zone0/temp`
  CELSIUS=`expr $TEMP / 1000`
  echo "Current Temp in Celsius is $CELSIUS"
  echo "Sleeping 10 seconds"
  echo "Control-C to exit loop"
  echo "" 
  sleep 10

done 

Any chance that could be tweaked to display CPU load as well?

You can add
vmstat 1 1
before the echo sleeping
that will give you a lot of perf data for that one second
OR you can do the following to display perf data for 10 seconds and temp

#!/bin/bash

while :
do
  TEMP=`cat  /sys/class/thermal/thermal_zone0/temp`
  CELSIUS=`expr $TEMP / 1000`
  echo "Current Temp in Celsius is $CELSIUS"
  vmstat 1 10
  echo "Control-C to exit loop"
  echo ""

done

Awesome....so....again....a noob...so I truly appreciate your patience...
How do I write this via my PuTTY session so it is saved/create a file?
(Sorry...Windows guy)