You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+70-7Lines changed: 70 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,29 +1,61 @@
1
-
# Edge device (e.g. raspberry pi) monitoring by means of a composite docker application on [Balena OS](https://www.balena.io/os/).
1
+
# Composite docker application with _"8"_ containers (2x Node-RED, 2x MQTT broker, Telegraf, InfluxDb, Grafana, Nginx) deployed on Raspberry Pi through [Balena](https://www.balena.io).
2
2
3
-
This repository describes a composite docker application that monitors the system resources of the device where it is deployed on. This application can be deployed through [BalenaCloud](https://www.balena.io/) on any arm device (e.g. a raspberry pi) running the [balena OS](https://www.balena.io/os/).
3
+
## Features
4
+
This project is actually a proof of concept to demonstrate the following features:
5
+
1. The ability to run **many** containers on a **Raspberry Pi 3 Model B+** (see [section 1. What](#1-what)).
6
+
2. The Built and Deployment of this multi container application using the **BalenaCloud** services (see [section 2. How to install ...](#2-how-to-install-this-application-on-an-edge-device)).
7
+
3. Monitoring the system resources of the raspberry pi using the **TIG** stack (see [section 3. System resource monitoring ...](#3-system-resource-monitoring-using-the-tig-stack-telegraf-influxdb--grafana)):
8
+
4. That **Grafana** is very nice and powerful tool to create dashboards (see [section 4. Grafana](#4-grafana)) and that it is easy to create or update those dashboards (see [section 4.1 Updating and adding ...](#41-updating--adding-new-grafana-dashboards)).
9
+
5. It is possible to run **multiple Node-RED instances** on the same device (see [section 5. Node-RED](#5-node-red)).
10
+
6. It is possible to run **multiple MQTT brokers** on the same device (see [section 6. MQTT brokers](#6-mqtt-broker)).
11
+
7. A **USB memory stick** connected to the pi can be used for storing specific data (in this case it is the influxdb data) (see [section 7. USB memory stick](#7-setup-of-the-usb-memory-stick-for-influxdb)).
12
+
8. It is possible to access the Grafana user interface and the 2 Node-RED editors **via the internet** (see [see section 8. Internet Access](#8-internet-access-via-balenas-public-url-and-nginx)).
4
13
5
-
It consists of the following four docker containers (= TIG stack + nginx)
14
+
## 1. What
15
+
This github repository describes a composite docker application consisting of **"8"** containers that can be deployed through [BalenaCloud](https://www.balena.io/) on any arm device (e.g. a [Raspberry Pi 3 Model B+](https://www.raspberrypi.org/products/raspberry-pi-3-model-b-plus/)) running the [balena OS](https://www.balena.io/os/).
6
16
17
+
So, this application consists of the following 8 docker containers (= TIG stack + 2x Node-RED + 2x MQTT broker + Nginx )
7
18
1.[Telegraf](https://www.influxdata.com/time-series-platform/telegraf/) - agent for collecting and reporting metrics and events
8
19
2.[Influxdb](https://www.influxdata.com/) - Time Series Database
9
20
3.[Grafana](https://grafana.com/) - create, explore and share dashboards
10
-
4.[nginx](http://nginx.org/en/docs/) - configured as reverse-proxyserver so that the http/https request becomes routed to grafana (port 30000).
21
+
4. 2x [Node-RED](https://nodered.org/) - flow based programming for the Internet of Things (accessible through path `/nodered` )
4.[nginx](http://nginx.org/en/docs/) - is open source software for web serving, reverse proxying, caching, load balancing,....
24
+
25
+
26
+
## 2. How to install this application on an edge device
27
+
It is very easy to install this application using the [BalenaCloud](https://www.balena.io/) services through following steps:
11
28
12
29
The Grafana user interface can be accessed (login and password is `admin`) at port 30000 of the host OS, but thanks to nginx (reverse proxy) it can also be accessed at port 80 of the host OS. This also means that you can access it through the `public device URL` that you can find in your [BalenaCloud](https://www.balena.io/) dashboard. In other words you can access your Grafana dashboards wherever you have internet access !
13
30
14
31
Here below a screenshot of the `system metrics` dashboard that is also provisioned by this application ( file is `grafana\dashboards\system metrics.json`)
## How to install this application on an edge device
19
-
This application can easily be installed through following steps:
20
35
1.[Balena Setup](https://www.balena.io/): 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).
21
36
2. clone this github repository (this can be done on any device where git is installed) through the following command `git clone https://github.com/janvda/balena-edge-device-monitoring.git` (instead of directly cloning the repository it migh be better to fork the github repository and then clone this forked repository).
22
37
3. Move into this repository by command `cd balena-edge-device-monitoring`
23
38
4. Add balena git remote endpoint by running the command `git remote add balena <USERNAME>@git.www.balena.io:<USERNAME>/<APPNAME>.git`
24
39
5. push the repository to balena by the command `git push balena master` (maybe you need to add the option `--force` the first time you are deploying).
## 3. System resource monitoring using the TIG Stack (Telegraf, Influxdb & Grafana)
44
+
The system resource monitoring is realized by the TIG stack and happens as follows:
45
+
1. The [Telegraf](https://www.influxdata.com/time-series-platform/telegraf/) container collects the system resource metrics (memory, CPU, disk, network, ...) of the raspberry pi device and sends them to
46
+
2. the [Influxdb](https://www.influxdata.com/) container that will store them in the influx database.
47
+
3. The [Grafana](https://grafana.com/) container has a dashboard (see screenshot below) showing these system metrics that it has retrieved from the influxdb.
48
+
49
+
## 4. Grafana
50
+
The [Grafana](https://grafana.com/) user interface can be accessed at port 3000 of the host OS.
51
+
The login and password is `admin`.
52
+
The name of the dashboard is `system metrics`.
53
+
54
+
Here below a screenshot of the `system metrics` dashboard that is also provisioned by this application ( file is `grafana\dashboards\system metrics.json`)
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):
29
61
@@ -33,6 +65,37 @@ If you want to add a new Grafana dashboard then this can be done through followi
33
65
4. Substitute the ID number you can fiInfluxDB system metrics dashboard]nd in that file just after field `"graphTooltip"` by `null`. E.g. ` "id": 1,` should be changed into ` "id": null,`
34
66
5. Commit your changes in git and push them to your balena git remote endpoint (`git push balena master`)
35
67
68
+
## 5. Node-RED
69
+
The application consists of 2 [Node-RED](https://nodered.org/) containers:
70
+
1.**node-red**: this editor is accessble through Host OS port and path : `<Host OS>:1880/node-red/`
71
+
2.**node-red-test** : this editor is accessble through Host OS port and path : `<Host OS>:1882/node-red-test/`
72
+
73
+
Note that both Node-RED editors are protected by a user name and a hashed password that must be set throught the environment variables `USERNAME` and `PASSWORD`. The [Node-RED security page](https://nodered.org/docs/security) describes how a password hash can be generated. You can set these environment variables using your [Balena dashboard](https://dashboard.balena-cloud.com) either under:
74
+
-*Application Environment Variables (E(X))* - this implies that both Node-RED instances will have the same username and password.
75
+
-*Service Variables (S(X))*
76
+
77
+
78
+
79
+
## 6. MQTT broker
80
+
This application consist of 2 [Mosquitto MQTT-brokers](https://mosquitto.org/):
81
+
1.**mqtt** which is listening to Host OS port 1883
82
+
2.**mqtt-test** which is listening to Host OS port 1884
83
+
84
+
## 7. Setup of the USB memory Stick for Influxdb
85
+
The *influxdb* container is configured so that its data will be stored on a USB memory stick connected to the raspberry that has label `influxdb` and that is formatted in the `ext4` format as is specified in the influxdb Dockerfile.
86
+
The script `my_entrypoint.sh` has the additional instructions to mount this USB memory stick inside the influxdb container.
87
+
88
+
Note that the current *Balena* version doesn't yet support the definition of a such a mounted drive in the docker compose yaml file therefore this is handled through the influxdb container setup as described here above.
89
+
90
+
## 8. Internet access via Balena's public URL and Nginx.
91
+
The [nginx](http://nginx.org/en/docs/) container has been configured so that when you enable the Balena public device URL that you can access the following applications over the internet:
92
+
-*Grafana* User Interface via `<public device URL>`
93
+
- Node-RED editor of the container *node-red* via `<public device URL>\node-red`
94
+
- Node-Red dashboard UI of the container *node-red* via `<public device URL>\node-red\ui`
95
+
- Node-RED editor of the container *node-red-test* via `<public device URL>\node-red-test`
96
+
- Node-RED dashboard UI of the container *node-red-test* via `<public device URL>\node-red-test\ui`
97
+
98
+
36
99
## Credits
37
100
1.[Initializing Grafana with preconfigured dashboards](https://ops.tips/blog/initialize-grafana-with-preconfigured-dashboards/)[(github repository)](https://github.com/cirocosta/sample-grafana)
38
101
2.[InfluxDB system metrics dashboard](https://grafana.com/dashboards/1138)
0 commit comments