Hilscher Community Forum
InfluxDB, Node-RED and Grafana - Printable Version

+- Hilscher Community Forum (https://forum.hilscher.com)
+-- Forum: netPI 3 - Docker featuring Industrial Raspberry Pi 3 platform (https://forum.hilscher.com/forum-1.html)
+--- Forum: Projects (https://forum.hilscher.com/forum-7.html)
+--- Thread: InfluxDB, Node-RED and Grafana (/thread-684.html)



InfluxDB, Node-RED and Grafana - Armin@netPI - January-6th-2021

Deploy multiple interrelated containers at a time the Docker function "stacks" can be used. To use it on netPI open the Docker web GUI portainer.io and then click the menu item "Stacks" to the left.

[attachment=391]

Then click "+Add stack", enter a name of your stack like "mystack" and click into the "Web editor" windows in the middle and paste the following compose data to it

Code:
version: "2"

services:

nodered:
   image: nodered/node-red:1.2.7-10-arm32v7
   ports:
     - "1880:1880"
   networks:
     - bridgeNetwork
   restart: always
   user: root

influxdb:
   image: influxdb:1.7.8
   restart: always
   ports:
     - "8086:8086"
   networks:
     - bridgeNetwork
   environment:
     - INFLUXDB_DB=db0
     - INFLUXDB_ADMIN_ENABLED=true
     - INFLUXDB_ADMIN_USER=admin
     - INFLUXDB_ADMIN_PASSWORD=12345678
     - INFLUXDB_USER=user
     - INFLUXDB_USER_PASSWORD=12345678

grafana:
   image: grafana/grafana:5.4.3
   restart: always
   ports:
     - "3000:3000"
   networks:
     - bridgeNetwork

networks:
   bridgeNetwork:
       driver: bridge
       ipam:
           driver: default
           config:
               - subnet: 172.30.0.0/24
                 gateway: 172.30.0.1       

Your screen will look like

[attachment=392]

The example compose data above contains information about to deploy 3 containers at a time
  • InfluxDB database to store data in time series manner
  • Grafana graphical tool for visualizing InfluxDB
  • Node-RED IoT tool to write to influxdb for testing

Click "Deploy the stack" and patiently wait for netPI to load and start all 3 containers. This may take 10 minutes. The web interface will report a warning message at the end in a orange colored window. This message can be ignored.

Your container overview screen will look like

[attachment=393]

Continue to
  • access Node-RED over "http://<ip address>:1880"
  • install influxdb node-red nodes called "node-red-contrib-influxdb"using the Node-RED embedded manage palette function
    [attachment=389]
  • import the small Node-RED test flow below to write to the database variable with "mytestdata" every second

Code:
[{"id":"f6f2187d.f17ca8","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"3cc11d24.ff01a2","type":"comment","z":"f6f2187d.f17ca8","name":"WARNING: please check you have started this container with a volume that is mounted to /data\\n otherwise any flow changes are lost when you redeploy or upgrade the container\\n (e.g. upgrade to a more recent node-red docker image).\\n  If you are using named volumes you can ignore this warning.\\n Double click or see info side panel to learn how to start Node-RED in Docker to save your work","info":"\nTo start docker with a bind mount volume (-v option), for example:\n\n```\ndocker run -it -p 1880:1880 -v /home/user/node_red_data:/data --name mynodered nodered/node-red\n```\n\nwhere `/home/user/node_red_data` is a directory on your host machine where you want to store your flows.\n\nIf you do not do this then you can experiment and redploy flows, but if you restart or upgrade the container the flows will be disconnected and lost. \n\nThey will still exist in a hidden data volume, which can be recovered using standard docker techniques, but that is much more complex than just starting with a named volume as described above.","x":350,"y":80,"wires":[]},{"id":"dc05ff72.ee1dd","type":"influxdb out","z":"f6f2187d.f17ca8","influxdb":"583af9d1.9aae98","name":"","measurement":"mytestdata","precision":"","retentionPolicy":"","database":"database","precisionV18FluxV20":"ms","retentionPolicyV18Flux":"","org":"organisation","bucket":"bucket","x":510,"y":300,"wires":[]},{"id":"d9436c1e.e3ffc","type":"inject","z":"f6f2187d.f17ca8","name":"Write timestamp every second","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"1","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":250,"y":220,"wires":[["dc05ff72.ee1dd"]]},{"id":"583af9d1.9aae98","type":"influxdb","hostname":"influxdb","port":"8086","protocol":"http","database":"db0","name":"local Influx database","usetls":false,"tls":"","influxdbVersion":"1.x","url":"http://localhost:8086","rejectUnauthorized":true}]

Your Node-RED screen will look like this

[attachment=386]

To visualize the periodically written data 
  • visit grafana web visualization over "http://<ip address>:3000"
  • Login with user "admin" and password "admin" the first time and specify a new password when requested. 
  • click "add data source"
  • click "influxDB" logo
  • as name enter e.g. "myinfluxdb"
  • as URL specify "http://influxdb:8086" which is the name of the influx container
  • as auth check "basic auth" method
  • as basic auth user enter "admin" (as determined for influxdb container in compose data environment variable)
  • as basic auth password enter "12345678"(as determined as influxdb container password for user in compose data environment variable)
  • as database in InfluxDB Details enter "db0"(as determined as influxdb database name in compose data environment variable)
  • as user in InfluxDB Details enter "user" (as determined as user name in compose data environment variable)
  • as password in InfluxDB Details enter "12345678" (as determined for influx container as user password in compose data environment variable)

Your grafana screen will look like

[attachment=387]

As next
  • click "home"
  • click "New dashboard"
  • click the "graph" icon
  • click "Panel title/edit"
  • change Data source in the screen middle from "default" to "myinfluxdb"
  • click "FROM" ... "select measurement" and then select "mytestdata"

Your grafana screen will look like

[attachment=388]
  • click disk symbol in top menu the save the dashboard
  • Enjoy the visualized data

Your screen finally will look like

[attachment=385]