Curious about your RPI's wellbeing?

In this subforum you can show projects you have made, or you are busy with. Please create your own topic.

Moderator: leecollings

Post Reply
Tukker
Posts: 675
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Curious about your RPI's wellbeing?

Post by Tukker »

Here's a short script that displays some information about your RPI

Code: Select all

#!/bin/bash
#
# Custom welcome screen - Clean version
#

echo
echo "==========================================="
echo " - Hostname............: $(hostname)"
echo " - Model...............: $(cat /proc/device-tree/model | tr -d '\0')"
echo " - Operating system....: $(. /etc/os-release; echo $VERSION_CODENAME)"
echo "==========================================="
echo "  $(date +"%A, %e %B %Y, %H:%M:%S")"
echo "  Uptime: $(uptime -p | sed 's/up //')"

CPU_TEMP=$(vcgencmd measure_temp | cut -d= -f2)
LOAD_AVG=$(awk '{print $1", "$2", "$3}' /proc/loadavg)
DISK_INFO=$(df -h / | awk 'NR==2{print "Free: "$4" | Used: "$3" "$5}')
MEM_INFO=$(free -h | awk '/Mem:/ {print "Used: "$3" | Free: "$4" | Total: "$2}')
LOCAL_IP=$(hostname -I | awk '{for(i=1;i<=NF;i++) if ($i ~ /^[0-9]+\./) {print $i; exit}}')
PUBLIC_IP=$(curl -4 -s ifconfig.me || echo "N/A")

echo "  CPU Temperature....: ${CPU_TEMP}"
echo "  Load Averages......: ${LOAD_AVG}"
echo "  Disk Space.........: ${DISK_INFO}"
echo "  Memory (RAM).......: ${MEM_INFO}"
echo "  Local IP...........: ${LOCAL_IP}"
echo "  Public IP..........: ${PUBLIC_IP}"
echo "==========================================="
# Footer
echo
echo "  Info published by /etc/profile.d/welcome.sh"
echo "  (Shortcut alias: sysinfo)"
echo
Place the file in /etc/profile.d and off you go.
It displays info about your RPI in the terminal after openingg an SSH session.

I made an alias as well in ~/.bashrc
# sysinfo
alias sysinfo='bash /etc/profile.d/welcome.sh'
After that go source ~/.bashrc and whenever you need to remember your external IP or your OS, just type sysinfo.

Here's the display:
===========================================
- Hostname............: RPI3
- Model...............: Raspberry Pi 3 Model B Plus Rev 1.3
- Operating system....: bullseye
===========================================
maandag, 26 januari 2026, 23:14:45
Uptime: 7 hours, 45 minutes
CPU Temperature....: 39.2'C
Load Averages......: 0.05, 0.16, 0.17
Disk Space.........: Free: 49G | Used: 7,9G 14%
Memory (RAM).......: Used: 164Mi | Free: 409Mi | Total: 921Mi
Local IP...........: 192.168.1.18
Public IP..........: 185.45.23.237
===========================================

Info published by /etc/profile.d/welcome.sh
(Shortcut alias: sysinfo)
Bugs bug me.
User avatar
waltervl
Posts: 7023
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2026.3
Location: NL
Contact:

Re: Curious about your RPI's wellbeing?

Post by waltervl »

You are aware there is a motherbord sensor hardware gateway that does approximately the same? And so even keeps track of the sensor history?

https://wiki.domoticz.com/Motherboard_sensors
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Tukker
Posts: 675
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Re: Curious about your RPI's wellbeing?

Post by Tukker »

waltervl wrote: Tuesday 27 January 2026 0:18 You are aware there is a motherbord sensor hardware gateway that does approximately the same? And so even keeps track of the sensor history?

https://wiki.domoticz.com/Motherboard_sensors
I am Walter, I am.
The approximately is the difference.
Bugs bug me.
User avatar
waltervl
Posts: 7023
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2026.3
Location: NL
Contact:

Re: Curious about your RPI's wellbeing?

Post by waltervl »

If I am curious about the wellbeing of the my Domoticz server I can check it in Domoticz from everywhere I can access Domoticz. I dont have to go to my server, ssh into it and run the script...
Just my thoughts ;-)
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Tukker
Posts: 675
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Re: Curious about your RPI's wellbeing?

Post by Tukker »

You're right Walter, you're right!
Bugs bug me.
Tukker
Posts: 675
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Re: Curious about your RPI's wellbeing?

Post by Tukker »

I adapted the code a bit to be able to produce a comprehensive sysinfo text sensor.

Code: Select all

#!/bin/bash

# Haal alle variabelen op
HOSTNAME=$(hostname)
MODEL=$(cat /proc/device-tree/model | tr -d '\0')
OS=$(. /etc/os-release; echo $VERSION_CODENAME)
DATE_STR=$(date +"%A, %e %B %Y, %H:%M") # Zonder seconden
CPU_TEMP=$(vcgencmd measure_temp | cut -d= -f2)
LOAD_AVG=$(awk '{print $1", "$2", "$3}' /proc/loadavg)
DISK_INFO=$(df -h / | awk 'NR==2{print "Free: "$4" | Used: "$3" "$5}')
MEM_INFO=$(free -h | awk '/Mem:/ {print "Used: "$3" | Free: "$4" | Total: "$2}')
LOCAL_IP=$(hostname -I | awk '{for(i=1;i<=NF;i++) if ($i ~ /^[0-9]+\./) {print $i; exit}}')
PUBLIC_IP=$(curl -4 -s --max-time 3 ifconfig.me || echo "N/A")

# Controleer of Domoticz om compacte info vraagt voor de text sensor
if [ "$1" == "compact" ]; then
    echo "Hostname: ${HOSTNAME}"
    echo "Local IP: ${LOCAL_IP}"
    echo "Public IP: ${PUBLIC_IP}"
    echo "${MODEL}"
    echo "OS: ${OS}"
    echo ""
    echo "CPU Temp: ${CPU_TEMP}"
    echo "Load: ${LOAD_AVG}"
    echo "Disk: ${DISK_INFO}"
    echo "Memory: ${MEM_INFO}"
else
    # Je originele SSH layout
    echo ""
    echo "==========================================="
    echo " - Hostname............: ${HOSTNAME}"
    echo " - Model...............: ${MODEL}"
    echo " - Operating system....: ${OS}"
    echo "==========================================="
    echo "  $(date +"%A, %e %B %Y, %H:%M:%S")"
    echo "  Uptime: $(uptime -p | sed 's/up //')"
    echo "  CPU Temperature....: ${CPU_TEMP}"
    echo "  Load Averages......: ${LOAD_AVG}"
    echo "  Disk Space.........: ${DISK_INFO}"
    echo "  Memory (RAM).......: ${MEM_INFO}"
    echo "  Local IP...........: ${LOCAL_IP}"
    echo "  Public IP..........: ${PUBLIC_IP}"
    echo "==========================================="
fi
The bash scripts needs a dzVents script to be able to display the readings in a text sensor.

Code: Select all

return {
    on = {
        timer = { 'every minute' },
        customEvents = { 'GetSysInfoManual' }
    },
    logging = {
        level = domoticz.LOG_INFO,
        marker = "--- sysinfo ---"
    },
    execute = function(domoticz, item)
        domoticz.log('sysinfo: Start systeem-update (trigger: ' .. item.trigger .. ')', domoticz.LOG_INFO)
        
        local handle = io.popen("/bin/bash /etc/profile.d/welcome.sh compact 2>&1")
        if (handle) then
            local result = handle:read("*a")
            handle:close()

            if (result and result ~= "") then
                local sensor = domoticz.devices('sysinfo')
                if (sensor) then
                    -- Strip eventuele kleurcodes
                    local cleanResult = result:gsub('[\27\155][][()#;?%d]*[A-PRZcf-ntqry=><~]', '')
                    sensor.updateText(cleanResult)
                    domoticz.log('sysinfo: Dashboard succesvol ververst.', domoticz.LOG_INFO)
                end
            end
        end
    end
}
Adapt the code to run the script every x minutes or like I do once a day.
Add a text sensor with the name 'sysinfo' and it works

Like @waltervl suggested I installed the Motherboard sensors plug-in as well.
OK, it shows some information like Internal temperature, Memory usage, Process Usage, CPU usage, HDD/Boot but uses 5 sensors for it. What is the use of HDD/Boot % when you don't know the size of the card.

My script has one disadvantage and that is the text sensor make the system grow rapidly.
To prevent massive growth I am using a script to vacuum the Domotizc database once a week.
I documented the cleanup procedure here.
sysinfo.png
sysinfo.png (18.82 KiB) Viewed 2471 times
cleanup.png
cleanup.png (24.45 KiB) Viewed 2470 times
Bugs bug me.
Post Reply