Last active
June 18, 2020 19:00
-
-
Save natcl/0aaf7a0b9bf82a4321458d8ae6828bd3 to your computer and use it in GitHub Desktop.
Node-RED + InfluxDB + Grafana + Mongo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: '2' | |
services: | |
nodered1: | |
depends_on: | |
- mosquitto | |
image: nodered/node-red-docker:0.17.5 | |
ports: | |
- "1884:1880" | |
restart: always | |
environment: | |
- TZ=America/Montreal | |
volumes: | |
- /data | |
nodered2: | |
depends_on: | |
- mosquitto | |
image: nodered/node-red-docker:0.17.5 | |
ports: | |
- "1885:1880" | |
restart: always | |
environment: | |
- TZ=America/Montreal | |
volumes: | |
- /data | |
mosquitto: | |
image: eclipse-mosquitto | |
restart: always | |
environment: | |
- TZ=America/Montreal | |
mongo: | |
image: mongo:3.5.7 | |
restart: always | |
environment: | |
- TZ=America/Montreal | |
influxdb: | |
image: influxdb | |
ports: | |
- "8086:8086" | |
grafana: | |
depends_on: | |
- influxdb | |
image: grafana/grafana | |
ports: | |
- "3000:3000" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"id": "c7b61643.803398", | |
"type": "tab", | |
"label": "Flow 1" | |
}, | |
{ | |
"id": "a3ae05f8.66e81", | |
"type": "mqtt-broker", | |
"z": "", | |
"broker": "mosquitto", | |
"port": "1883", | |
"clientid": "", | |
"usetls": false, | |
"compatmode": true, | |
"keepalive": "60", | |
"cleansession": true, | |
"willTopic": "", | |
"willQos": "0", | |
"willRetain": "false", | |
"willPayload": "", | |
"birthTopic": "", | |
"birthQos": "0", | |
"birthRetain": "false", | |
"birthPayload": "" | |
}, | |
{ | |
"id": "56c279bd.4fc9e8", | |
"type": "influxdb", | |
"z": "", | |
"hostname": "influxdb", | |
"port": "8086", | |
"protocol": "http", | |
"database": "metrics", | |
"name": "", | |
"usetls": false, | |
"tls": "" | |
}, | |
{ | |
"id": "f12769fc.caf398", | |
"type": "mongodb2", | |
"z": "", | |
"uri": "mongodb://mongo:27017/metrics", | |
"name": "metrics", | |
"options": "", | |
"parallelism": "-1" | |
}, | |
{ | |
"id": "e88586bc.f8145", | |
"type": "inject", | |
"z": "c7b61643.803398", | |
"name": "", | |
"topic": "test", | |
"payload": "", | |
"payloadType": "date", | |
"repeat": "", | |
"crontab": "", | |
"once": false, | |
"x": 160, | |
"y": 100, | |
"wires": [ | |
[ | |
"1fb26dec.2062ea" | |
] | |
] | |
}, | |
{ | |
"id": "1fb26dec.2062ea", | |
"type": "mqtt out", | |
"z": "c7b61643.803398", | |
"name": "", | |
"topic": "", | |
"qos": "", | |
"retain": "", | |
"broker": "a3ae05f8.66e81", | |
"x": 404.5, | |
"y": 101, | |
"wires": [] | |
}, | |
{ | |
"id": "78777795.feaa9", | |
"type": "influxdb in", | |
"z": "c7b61643.803398", | |
"influxdb": "56c279bd.4fc9e8", | |
"name": "", | |
"query": "SELECT * from temperature", | |
"rawOutput": false, | |
"precision": "", | |
"retentionPolicy": "", | |
"x": 450, | |
"y": 440, | |
"wires": [ | |
[ | |
"a1e517b.c303368" | |
] | |
] | |
}, | |
{ | |
"id": "6fd3a49.44df5dc", | |
"type": "influxdb out", | |
"z": "c7b61643.803398", | |
"influxdb": "56c279bd.4fc9e8", | |
"name": "", | |
"measurement": "temperature", | |
"precision": "", | |
"retentionPolicy": "", | |
"x": 620, | |
"y": 320, | |
"wires": [] | |
}, | |
{ | |
"id": "49a79811.aa9e5", | |
"type": "inject", | |
"z": "c7b61643.803398", | |
"name": "", | |
"topic": "", | |
"payload": "", | |
"payloadType": "date", | |
"repeat": "", | |
"crontab": "", | |
"once": false, | |
"x": 140, | |
"y": 440, | |
"wires": [ | |
[ | |
"78777795.feaa9" | |
] | |
] | |
}, | |
{ | |
"id": "a1e517b.c303368", | |
"type": "debug", | |
"z": "c7b61643.803398", | |
"name": "", | |
"active": true, | |
"console": "false", | |
"complete": "false", | |
"x": 770, | |
"y": 440, | |
"wires": [] | |
}, | |
{ | |
"id": "e6c3299f.5cc748", | |
"type": "random", | |
"z": "c7b61643.803398", | |
"name": "", | |
"low": "0", | |
"high": "30", | |
"inte": "true", | |
"x": 360, | |
"y": 320, | |
"wires": [ | |
[ | |
"6fd3a49.44df5dc" | |
] | |
] | |
}, | |
{ | |
"id": "538a7f99.32532", | |
"type": "inject", | |
"z": "c7b61643.803398", | |
"name": "", | |
"topic": "", | |
"payload": "", | |
"payloadType": "date", | |
"repeat": "", | |
"crontab": "", | |
"once": false, | |
"x": 140, | |
"y": 320, | |
"wires": [ | |
[ | |
"e6c3299f.5cc748" | |
] | |
] | |
}, | |
{ | |
"id": "d42edea6.6f3618", | |
"type": "mongodb2 in", | |
"z": "c7b61643.803398", | |
"service": "_ext_", | |
"configNode": "f12769fc.caf398", | |
"name": "", | |
"collection": "metrics", | |
"operation": "insert", | |
"x": 540, | |
"y": 600, | |
"wires": [ | |
[] | |
] | |
}, | |
{ | |
"id": "6134e950.680d68", | |
"type": "inject", | |
"z": "c7b61643.803398", | |
"name": "", | |
"topic": "", | |
"payload": "", | |
"payloadType": "date", | |
"repeat": "", | |
"crontab": "", | |
"once": false, | |
"x": 160, | |
"y": 600, | |
"wires": [ | |
[ | |
"f03fb9c8.f6238" | |
] | |
] | |
}, | |
{ | |
"id": "f03fb9c8.f6238", | |
"type": "template", | |
"z": "c7b61643.803398", | |
"name": "", | |
"field": "payload", | |
"fieldType": "msg", | |
"format": "handlebars", | |
"syntax": "mustache", | |
"template": "{\n \"timestamp\": {{payload}},\n \"hello\": 4\n}", | |
"output": "json", | |
"x": 310, | |
"y": 600, | |
"wires": [ | |
[ | |
"d42edea6.6f3618" | |
] | |
] | |
}, | |
{ | |
"id": "fe2c58ce.9d30b8", | |
"type": "mongodb2 in", | |
"z": "c7b61643.803398", | |
"service": "_ext_", | |
"configNode": "f12769fc.caf398", | |
"name": "", | |
"collection": "metrics", | |
"operation": "find.toArray", | |
"x": 560, | |
"y": 720, | |
"wires": [ | |
[ | |
"acd00937.6c1c5" | |
] | |
] | |
}, | |
{ | |
"id": "aa57e7e3.76c1f8", | |
"type": "inject", | |
"z": "c7b61643.803398", | |
"name": "", | |
"topic": "", | |
"payload": "{}", | |
"payloadType": "json", | |
"repeat": "", | |
"crontab": "", | |
"once": false, | |
"x": 150, | |
"y": 720, | |
"wires": [ | |
[ | |
"fe2c58ce.9d30b8" | |
] | |
] | |
}, | |
{ | |
"id": "acd00937.6c1c5", | |
"type": "debug", | |
"z": "c7b61643.803398", | |
"name": "", | |
"active": true, | |
"console": "false", | |
"complete": "false", | |
"x": 810, | |
"y": 720, | |
"wires": [] | |
}, | |
{ | |
"id": "163102b6.d9bee5", | |
"type": "comment", | |
"z": "c7b61643.803398", | |
"name": "MQTT test send, check the other Node-RED instance", | |
"info": "", | |
"x": 260, | |
"y": 40, | |
"wires": [] | |
}, | |
{ | |
"id": "eb580cef.d3f088", | |
"type": "comment", | |
"z": "c7b61643.803398", | |
"name": "Write random values to influxDB", | |
"info": "", | |
"x": 190, | |
"y": 260, | |
"wires": [] | |
}, | |
{ | |
"id": "a6628c2c.c1b988", | |
"type": "comment", | |
"z": "c7b61643.803398", | |
"name": "Query those values", | |
"info": "", | |
"x": 150, | |
"y": 380, | |
"wires": [] | |
}, | |
{ | |
"id": "160a38c.74fe847", | |
"type": "comment", | |
"z": "c7b61643.803398", | |
"name": "Write document to MongoDB", | |
"info": "", | |
"x": 180, | |
"y": 540, | |
"wires": [] | |
}, | |
{ | |
"id": "2473fc37.c91fbc", | |
"type": "comment", | |
"z": "c7b61643.803398", | |
"name": "Query documents", | |
"info": "", | |
"x": 150, | |
"y": 660, | |
"wires": [] | |
} | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[{"id":"c1793785.3f81b8","type":"tab","label":"Flow 1"},{"id":"6ec65236.003684","type":"mqtt-broker","z":"","broker":"mosquitto","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"willTopic":"","willQos":"0","willRetain":"false","willPayload":"","birthTopic":"","birthQos":"0","birthRetain":"false","birthPayload":""},{"id":"4971c2ff.04042c","type":"mqtt in","z":"c1793785.3f81b8","name":"","topic":"test","qos":"2","broker":"6ec65236.003684","x":130,"y":80,"wires":[["f04d4858.6bd388"]]},{"id":"f04d4858.6bd388","type":"debug","z":"c1793785.3f81b8","name":"","active":true,"console":"false","complete":"false","x":350,"y":80,"wires":[]}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# We create the docker instances | |
docker-compose up -d | |
# We create an InfluxDB database called metrics | |
docker exec -it app_influxdb_1 influx -execute "CREATE DATABASE metrics" | |
# We create a mongodb database called metrics and a collection called metrics | |
docker exec -it app_mongo_1 mongo --eval "metrics = db.getSiblingDB('metrics');metrics.createCollection('metrics');" | |
# We npm install nodes in the Node-RED dockers | |
docker exec -it app_nodered1_1 npm install --prefix /data node-red-contrib-influxdb node-red-contrib-mongodb2 | |
docker exec -it app_nodered2_1 npm install --prefix /data node-red-contrib-influxdb node-red-contrib-mongodb2 | |
# We copy the flow files to the corresponding docker instances | |
docker cp flows1.json app_nodered1_1:/data/flows.json | |
docker cp flows2.json app_nodered2_1:/data/flows.json | |
# We restart Node-RED | |
docker-compose restart nodered1 | |
docker-compose restart nodered2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment