Cubox Temperature Monitoring

SolidRun Cubox

I use SolidRun Cubox device instead of widely used Raspberry Pi devices as my small home server next to the Synology NAS. Cubox runs my Pi-hole DNS server and Unify management.

During the summer ☀️ it gets pretty hot 🥵 in the rack, although there is a small fan at the top, so temperature monitoring is essential. I use M/Monit for simple monitoring and notifications via Pushover… but a nice visual notification in the shell, that’s what I always wanted 🙂

Powerlevel10k theme

I found this example for the Powerlevel10k theme that I use in zsh p10k extensible:

p10k-extensible-pic

… and I have implemented it this way:

Added this piece of code at the end of my .p10k.zsh file:

function prompt_my_cpu_temp() {
    integer cpu_temp="$(</etc/armbianmonitor/datasources/soctemp) / 1000"
    if (( cpu_temp >= 45 )); then
        p10k segment -s HOT -f red -i '🔥' -t "${cpu_temp}°C"
    elif (( cpu_temp >= 40 )); then
        p10k segment -s WARM -f yellow -i '🌡' -t "${cpu_temp}°C"
    fi
}
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS+=my_cpu_temp

Now my prompt looks like this:

cubox-ssh-temp

M/Monit

Just for the record, for M/Monit I use this script cubox-temperature.sh:

#!/bin/bash

function getboardtemp() {
        if [ -f /etc/armbianmonitor/datasources/soctemp ]; then
                read raw_temp </etc/armbianmonitor/datasources/soctemp 2>/dev/null
                if [ ! -z $(echo "$raw_temp" | grep -o "^[1-9][0-9]*\.\?[0-9]*$") ] && (( $(echo "${raw_temp} < 200" |bc -l) )); then
                        # Allwinner legacy kernels output degree C
                        board_temp=${raw_temp}
                else
                        board_temp=$(awk '{printf("%d",$1/1000)}' <<<${raw_temp})
                fi
        elif [ -f /etc/armbianmonitor/datasources/pmictemp ]; then
                # fallback to PMIC temperature
                board_temp=$(awk '{printf("%d",$1/1000)}' </etc/armbianmonitor/datasources/pmictemp)
        fi
} # getboardtemp

getboardtemp
echo $board_temp

Update: 03/09/2020

Today I logged in to my system and noticed that the temperature info is missing from the prompt. I tried to update oh-my-zsh, checked whether the temperature reading works and some other stuff… honestly it took me a while, until I noticed that there is no else condition in the function.

elif (( cpu_temp >= 40 )); then

so as the temperature, outside and in the garage where the devices are located, has decreased recently also the prompt stopped to show the CPU temperature.

And that’s all folks!