Giter Club home page Giter Club logo

mqtt-diag-pi's Introduction

Raspberry Pi Diagnostics - MQTT

We present a Raspberry Valley approach to monitoring Pi diagnostics via MQTT.

Scenario: your killer app is not behaving as it should. Maybe the CPU is overloaded, maybe the Pi is overheating, maybe you have consumed all memory. Enter the diagnostics tool: you can monitor remotely, or in a console window how your app is consuming resources.

mqtt-diag-pi in action

This is a Python script, which collects system data and sends them to MQTT diagnostics topics, and to the console. If you use our Raspberry Pi IoT Device, then simply clone the script and run it. However, you don't have to have the image available: in such a case, just check the pre-requisites page and install only the required components.

The script works both with Python 2.x and Python 3.x. On the Dashboard side, you can use our Node-RED configuration for a Node-RED Dashboard, or use the message flow described below to send data say to Azure IoT Hub (or other solutions)

Diagnostics values sent

  • CPU Temperature [C]
  • CPU Load Percentage [%]
  • Disk Usage Percentage [%]
  • Memory Usage Percentage [%]

Further, we send a cumulative json object with all values at once.

All values are sent to topics using the pattern below. You can change the pattern in config.py

system/<hostname>/<measurementname>

Below is an example where we monitor a camera solution for debugging, using a remote MQTT server (with Node-RED and Node-RED Dashboard) for impact of configuration settings.

monitoring

Note: you can get quickly started by modifying our dashboard: just import the file content from mqtt-diag-pi-ui.json into your Node-RED dashboard and get hacking to your liking. Please make sure that you first replace all occurences of "MYHOSTNAME" with the hostname of the PI you are monitoring

replace here

You can also replace the hostname directly in Node-RED MQTT nodes, as shown below:

replace in nodered

Pre-requisites

Before cloning the project, install the following components:

  • Install Git
sudo apt-get install git
  • We Assume you have pip installed on your device. If not, open up the terminal and type:
sudo apt-get install python-pip

if using Python3 (recommended), install this instead:

sudo apt-get install python3-pip
  • Either run the Raspberry Pi IoT Device, or install MQTT only. In the latter case, you will need to subscribe to the topics described below, or make use of the console monitoring only. For installation of MQTT (Mosquitto), you can find our guide here. Follow the full guide, you need the Paho libraries as well. Or simply follow the commands below:
sudo apt-get install mosquitto
sudo apt-get install mosquitto-clients
sudo pip install paho-mqtt
sudo pip install psutil

with Python 3, use this instead:

sudo pip3 install psutil
  • Apart from libraries listed above, you will also need to install logzero (our logging solution of choice for this project)
sudo pip install logzero

And alternatively for Python 3:

sudo pip3 install logzero

Running Diagnostics

You have several options on how to run the diagnostics.

  • First, clone the repository to your Pi and navigate to the directory
  • Now run the Python script. We like to run it directly, so you might want to do the following:
chmod +x mqtt-diag-pi.py
./mqtt-diag-pi.py

This basically sets the script as an executable and you can run it standalone. You can of course always ignore the above, and use the standard approach:

python mqtt-diag-pi.py
  • With the default settings, your local MQTT server now receives updates every 5 seconds, and also your console log gives a summary of the measurements
  • Time to get creative and use NODE-RED dashobard itself, or send the data to another machine running MQTT

About

Raspberry Valley is a maker community in Karlskrona, Sweden, sponsored by Dynapac. We run makerspaces every week, working with Raspberry Pis, Arduinos and other interesting hardware.

This repository is here to support our community of makers. A lot of our achievements are based and inspired by the community at large. We wish to pay back and share our experiences and lessons learned. Join us!

You can find our pages here: Raspberry Valley. You can also join us on Twitter or check Docker Hub for images of interest.

Links

Raspberry Valley makerspace links

mqtt-diag-pi's People

Contributors

raspberryvalley avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.