I finally bought a Raspberry Pi 4!
It’s currently running LibreOS, a lightweight Linux distro for Kodi. I’ve installed the librespot plugin, turning the Pi into a Spotify Connect device, as well as this Netflix plugin from CastagnaIT, which works great. Overall, the Pi 4 can really perform as a media device.
I was curious what kind of load the HD video streaming was putting on the Pi, and just how well the Passive Cooling from PiShop was doing. With the Pi’s documentation and many examples on the web, I decided to write a small bash script to perform a glorified watch command.
It’s about as simple as it gets. You can view the the code below, or in the GitHub repo.
Here’s a demo of the script running:
The Code
#!/bin/bash
# Script: pi_temp_log.sh
# Use: Logs the CPU and GPU temperatures and clock values of your Raspberry Pi 4
# ASCII art adapted from user b3n on raspberrypi.org
# Author: Lane Clark github.com/lclarko
# License: GPL-3.0
###########
echo "
.~~. .~~. Raspberry Pi 4
'. \ ' ' / .' GPU + CPU
.~ .~~~..~. Temp + Clock
: .~.'~'.~. : Monitor
~ ( ) ( ) ~
( : '~'.~.'~' : )
~ .~ ( ) ~. ~
( : '~' : )
'~ .~~~. ~'
'~'"
# Path to LOG_FILE and log file creation
LOG_FILE=./pi_temp.log
if [[ ! -f "./pi_temp.log" ]]
then touch pi_temp.log && echo "Created pi_temp.log"
fi
echo -e "$(date) @ $(hostname)" | tee -a ${LOG_FILE}
echo -e "-------------------------------------------" | tee -a ${LOG_FILE}
echo -e "CPU\t\t\tGPU\t\t\tTIME" | tee -a ${LOG_FILE}
while true; do
# Assigning measurments to variables
cpu_temp=$(cat /sys/class/thermal/thermal_zone0/temp)
gpu_temp=$(vcgencmd measure_temp | cut -d = -f2 | cut -d . -f 1)
arm_clock=$(vcgencmd measure_clock arm | cut -d = -f2)
gpu_clock=$(vcgencmd measure_clock core | cut -d = -f2)
# Return all the values + 8601 timestamp
echo -e "$((cpu_temp/1000))'C\t$((arm_clock/1000000))MHz\t\t$((gpu_temp))'C\t$((gpu_clock/1000000))MHz\t\t$(date -I'seconds')" | tee -a ${LOG_FILE}
# Measurement interval
sleep 3
done
This post was originally published on on Sep 13, 2020: Logging Raspberry Pi CPU and GPU Data.