Show system stats from your various local network Raspberry Pies

If you’re like me, you have several of these pies running around your house performing various tasks and making your life easier :slight_smile: However they need your love and attention, too!

So I created a script that runs in each pi. The script publishes to my HASS MQTT broker some basic system data so I know its health and activity.

You can find the code script I wrote for this purpose at https://github.com/andres-leon/rbp-mqtt-stats.

Looking forward to your comments and ideas. One taht comes to mind is to create automations that would actually notify me when one of the Pies is failing, running out of disk space, cpu getting too hot, etc. I’m still learning HASS so that is a little out of my league right now.

Thanks!

7 Likes

I’ve been doing this using the Glances sensors, but this is a neat approach too.

Thank you. Had I known about this I might have used it… :slight_smile:

1 Like

But you exposed a whole new approach that may also open up new use cases for others.

All I did was read a doc. LOL…

Can you please tell how do you display value in home-assistant. I was able to get the values in raspberry pi y running the py file but i am not getting anything when i put it in sensors.yaml file. I am using the conf -

  • platform: mqtt
    state_topic: “rp/status1”
    name: “RP1 Status”
    value_template: ‘{{ value_json.status }}’

Still learning home-assistant.

I’m covering this with Glances and well, not perfect but it provides me notifications when Pis are going down or are overloaded with no issues.

Fighting a little with Openelec as I can’t find a way to install Glances on it.

I’m going to try this solution.

Thank you for sharing!!?

Take a look at https://github.com/andres-leon/rbp-mqtt-stats/blob/master/systemdata.py#L48

You’ll see that the payload i’m sending contains the values “datetimedatacollected”, “cpuusage”, “boottime”, “diskusage”, “cputemp” and “disktotal”. So the yaml code i’m using for my configuration will be something like this:

sensor rbp2_catfeeder_system:
- platform: mqtt
  state_topic: "rbp2_catfeeder/systemstatus"
  name: "Cat Feeder date data collected"
  value_template: '{{ value_json.datetimedatacollected }}'
- platform: mqtt
  state_topic: "rbp2_catfeeder/systemstatus"
  name: "Cat Feeder Boot Time"
  value_template: '{{ value_json.boottime }}'
- platform: mqtt
  state_topic: "rbp2_catfeeder/systemstatus"
  name: "Cat Feeder disk usage"
  unit_of_measurement: '%'
  value_template: '{{ value_json.diskusage }}'
- platform: mqtt
  state_topic: "rbp2_catfeeder/systemstatus"
  name: "Cat Feeder virtual memory"
  value_template: '{{ value_json.virtualmem }}'
  unit_of_measurement: '%'
- platform: mqtt
  state_topic: "rbp2_catfeeder/systemstatus"
  name: "Cat Feeder cpu usage"
  unit_of_measurement: '%'
  value_template: '{{ value_json.cpuusage }}'
- platform: mqtt
  state_topic: "rbp2_catfeeder/systemstatus"
  name: "Cat Feeder cpu temp"
  unit_of_measurement: '°F'
  value_template: '{{ value_json.cputemp }}'
- platform: mqtt
  state_topic: "rbp2_catfeeder/systemstatus"
  name: "Cat Feeder disk size"
  value_template: '{{ value_json.disktotal }}'

Hope that helps!

2 Likes

Thanks andresleon got it working now :slight_smile:

1 Like

Hmm… I suppose I could do some automation to notify me when certain thresholds such as high cpu temp, low disk space, etc are reached. Thanks for the idea! :slight_smile:

Need one more help in home-assistant config. How you use 2 brokers in home-assistant. I have 2 pi’s both running mqtt with same config you provided and both working independent but how do i get the 2nd pi’s broker in the 1st one which already has broker running on localhost.

A phrase you won’t see anywhere but here… :laughing:

3 Likes

Hello!

Thank you for sharing your script.
Manually executed the script, got the sysinfos and also “[Errno 32] Broken pipe” error.
The payload did not reach its destination.

If you have the time, help would be appreciated!

Home assistant is running the MQTT broker. This is the server that receives and keeps the messages coming from the mqtt clients (the RBPi’s you are monitoring.) Each RBPi you are monitoring is running the MQTT client to connect to the broker and send and receive messages from the MQTT server (HASS). So there is only ONE server (broker) running and multiple MQTT clients (one for each device you want to monitor.)

Hope this clears things.

I would make sure the device you are running the script from has network connectivity. Another issue may be that the MQTT broker is not running. Check that it is running by trying to connect from the very same device it is running. if you get the same error then you know that the MQTT broker is not running or is not configured correctly. Good luck!

1 Like

Thanks :slight_smile: will try that

life saver, thank you :slight_smile:

1 Like

Hello,

did as described on the GitHub radme file but at step #3 (executing the command python /home/pi/systemdata.py) i get the following error:

File “/home/pi/systemdata.py”, line 7

What i am doing wrong?

I would like to minitor my pi-hole system (running, load, disk,…) to ensure it works from my ha on another RasPi.

Thanks for your help.
Rehards, Ralf

Can you copy and paste the exact error you’re getting? Line 7 is importing time related functions.

from time import gmtime, strftime

in the python command line enter the line above and see what error you get.

Hello,

here is the complete error:

File "./systemdata.py", line 40
topic = <readacted topic to publish data>
        ^
SyntaxError: invalid syntax

EDIT: corrected the copy & paste above to show correct message.

Regards, Ralf

1 Like