Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Raspberry Pi Multi-Docker Stack (Node-RED, MQTT broker, Telegraf, InfluxDb, Grafana, Nginx) for deployment through Balena.

License

NotificationsYou must be signed in to change notification settings

ratte/LedBarPiStack

 
 

Repository files navigation

Features

This project is actually a proof of concept to demonstrate the following features:

  1. The ability to runmany containers on aRaspberry Pi 3 Model B+ (seesection 1. What).
  2. The Built and Deployment of this multi container application using theBalenaCloud services (seesection 2. How to install ...).
  3. Monitoring the system resources of the raspberry pi using theTIG stack (seesection 3. System resource monitoring ...):
  4. ThatGrafana is very nice and powerful tool to create dashboards (seesection 4. Grafana) and that it is easy to create or update those dashboards (seesection 4.1 Updating and adding ...).
  5. It is possible to runmultiple Node-RED instances on the same device (seesection 5. Node-RED).
  6. It is possible to runmultiple MQTT brokers on the same device (seesection 6. MQTT brokers).
  7. AUSB memory stick connected to the pi can be used for storing specific data (in this case it is the influxdb data) (seesection 7. USB memory stick).
  8. It is possible to access the Grafana user interface and the 2 Node-RED editorsvia the internet (seesee section 8. Internet Access).

1. What

This github repository describes a composite docker application consisting of"8" containers that can be deployed throughBalenaCloud on any arm device (e.g. aRaspberry Pi 3 Model B+) running thebalena OS.

So, this application consists of the following 8 docker containers (= TIG stack + 2x Node-RED + 2x MQTT broker + Nginx )

  1. Telegraf - agent for collecting and reporting metrics and events
  2. Influxdb - Time Series Database
  3. Grafana - create, explore and share dashboards
  4. 2xNode-RED - flow based programming for the Internet of Things (accessible through path/nodered )
  5. 2xMQTT-broker - lightweight message broker
  6. nginx - is open source software for web serving, reverse proxying, caching, load balancing,....

2. How to install this application on an edge device

It is very easy to install this application using theBalenaCloud services through following steps:

  1. Balena Setup: you need a BalenaCloud account and your edge device must be running the BalenaOs. You also need to create an application in your balena dashboard and associate your edge device to it (see balena documentation).
  2. clone this github repository (this can be done on any device where git is installed) through the following commandgit clone https://github.com/janvda/balena-node-red-mqtt-nginx-TIG-stack.git (instead of directly cloning the repository it migh be better to fork the github repository and then clone this forked repository).
  3. Move into this repository by commandcd balena-edge-device-monitoring
  4. Add balena git remote endpoint by running a command likegit remote add balena <USERNAME>@git.www.balena.io:<USERNAME>/<APPNAME>.git
  5. push the repository to balena by the commandgit push balena master (maybe you need to add the option--force the first time you are deploying).

build finished successful

3. System resource monitoring using the TIG Stack (Telegraf, Influxdb & Grafana)

The system resource monitoring is realized by the TIG stack and happens as follows:

  1. TheTelegraf container collects the system resource metrics (memory, CPU, disk, network, ...) of the raspberry pi device and sends them to
  2. theInfluxdb container that will store them in the influx database.
  3. TheGrafana container has a dashboard (see screenshot below) showing these system metrics that it has retrieved from the influxdb.

3.1 Telegraf

The table below specifies the environment variables that can be set in the Balena Device Service Variables panel for the Telegraf Service. Note that theDefault Value is defined indocker-compose.yml

NameDefault ValueDescription
interval60sFrequency at which metrics are collected
flush_interval60sFlushing interval (should not set <interval)

4. Grafana

TheGrafana user interface can be accessed at port 3000 of the host OS.The login and password isadmin.The name of the dashboard issystem metrics.

Here below a screenshot of thesystem metrics dashboard that is also provisioned by this application ( file isgrafana\dashboards\system metrics.json)

system metrics example top partsystem metrics example bottom part

4.1. Updating / Adding new Grafana Dashboards

If you want to add a new Grafana dashboard then this can be done through following steps (Updating an existing dashboard can be done in a similar way):

  1. Create the new dashboard using the Grafana UI.
  2. From the settings menu in Grafana UI selectView JSON and copy the complete json file (don't use the grafana UIexport feature as this will template the datasource and will not work due to that).
  3. Save the json contents you have copied in previous step into a new file in foldergrafana\dashboards with extension .json (e.g.mydashboard-02.json)
  4. Substitute the ID number you can find in that file just after field"graphTooltip" bynull. E.g. "id": 1, should be changed into "id": null,
  5. Commit your changes in git and push them to your balena git remote endpoint (git push balena master)

5. Node-RED

The application consists of 2Node-RED containers:

  1. node-red: its editor is accessble through Host OS port and path :<Host OS>:1880/node-red/
  2. node-red-test : its editor is accessble through Host OS port and path :<Host OS>:1882/node-red-test/

Note that both Node-RED editors are protected by a user name and ahashed password that must be set through the environment variablesUSERNAME andPASSWORD. TheNode-RED security page describes how a password hash can be generated. You can set these environment variables using yourBalena dashboard either under:

  • Application Environment Variables (E(X)) - this implies that both Node-RED instances will have the same username and password.
  • Service Variables (S(X))

Notes:

  1. node-red-data andnode-red-test-data are 2 named volumed used for the\data folder of respectivelynode-red andnode-red-test. Take care that thesettings.js is only copied during the initial deployment of the application. So when the application is redeployed e.g. due to changes, then thesettings.js is not recopied to the\data folder. (see alsoHow to copy a file to a named volume?)
  2. In order to assure that nodes installed throughnpm install are not lost after a restart of the container, you must assure that they are installed in the\data directory. So you must first do acd \data and then execute thenpm install .... command. This will assure that the node is correctly installed under folder\data\node_modules\ and that it will persist after restarts of the container.

6. MQTT broker

This application consist of 2Mosquitto MQTT-brokers:

  1. mqtt which is listening to Host OS port 1883
  2. mqtt-test which is listening to Host OS port 1884

7. Setup of the USB memory Stick for Influxdb

The data of the influxdb will be stored in the mount location\mnt\influxdb.Theinfluxdb container is configured (see Dockerfile and my_entrypoint.sh) so that a USB drive (e.g. a USB memory stick) with labelinfluxdb will be mounted to this mount location. It is currently also expecting (see Dockerfile) that this USB drive is formatted inext4 format.

If no USB drive (or memory stick) with labelinfluxdb is connected to the raspberry pi then the named volumeinfluxdb-data will be mounted to this location as is specified in thedocker-compose.yml file.

Notes

  1. the currentBalena version doesn't yet support the definition of a volume for such a mounted drive in the docker compose yaml file therefore this is handled through the influxdb container setup as described here above.
  2. It is not possible to mount the same USB drive also in telegraf container (I have tried that) and consequently telegraf is not able to report thedisk metrics for this USB drive.

8. Internet access via Balena's public URL and Nginx.

Thenginx container has been configured so that when you enable the Balena public device URL that you can access the following applications over the internet:

  • Grafana User Interface via<public device URL>
  • Node-RED editor of the containernode-red via<public device URL>\node-red
  • Node-Red dashboard UI of the containernode-red via<public device URL>\node-red\ui
  • Node-RED editor of the containernode-red-test via<public device URL>\node-red-test
  • Node-RED dashboard UI of the containernode-red-test via<public device URL>\node-red-test\ui

In case you get a502 Bad Gatewayerror or a message likeCannot GET /node-red-test/ when trying to access the above public URLs then this might be fixed by restarting the nginx container !

Credits

  1. Initializing Grafana with preconfigured dashboards(github repository)
  2. InfluxDB system metrics dashboard
  3. Grafana Series Part 1: Setting up InfluxDB, Grafana and Telegraf with Docker on Linux

About

Raspberry Pi Multi-Docker Stack (Node-RED, MQTT broker, Telegraf, InfluxDb, Grafana, Nginx) for deployment through Balena.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript87.8%
  • Dockerfile9.9%
  • Shell2.3%

[8]ページ先頭

©2009-2025 Movatter.jp