IOTstack icon indicating copy to clipboard operation
IOTstack copied to clipboard

Troubles connecting Grafana to Influxdb <Solved>

Open stevenveenma opened this issue 4 years ago • 2 comments

I am trying to get Grafana to work with Influxdb on my dockerized RPI. I have done this earlier on another RPI without Docker and that works fine. Some starting points: I created a database in Influxdb called P1 I receive messages by MQTT which are stored in P1 using Python Using the Influxdb terminal I can select and show the contents of P1 I have no specific/additional settings for Influxdb or Grafana I startup Grafana with the browser using <IP>:3000 and select connect datasources influxdb Then the settings: http: http://localhost:8086 Server(default) Basic authentication Grafana Influxdb details database: P1 Credentials: default (root/root) http method: GET

There is no logging in /home/pi/IOTstack/volumes/grafana/log. Portainer provides me with some logging:

2019/11/25 09:19:56 http: proxy error: dial tcp 127.0.0.1:8086: connect: connection refused,

Apparently something wrong with proxy: how to solve this?

Just found the solution of this long story: I use http://influxdb:8086 instead of localhost. Now Grafana can connect the database and I can make my graphs.

Don't know if I missed some information on in this repository, But probably it helps me and others to give some guidance/examples to connect. For me confusing is that I can connect from Python to Influxdb without any problems, but Grafana needs specific threatment.

stevenveenma avatar Nov 25 '19 09:11 stevenveenma

I suffered the same mis-step but in my case it was trying to write into Influx databases from Node-Red. By the time I got to the Grafana side, I knew what to do.

For the benefit of others following the discussion, the solution of:

	«containername»:«port»

is more general than just Influx. It applies to any cross-container comms.

In the case of Node-Red writing to the measurement "hiking" (a kind of electricity meter) in my "power" database:

Screen Shot 2019-11-25 at 22 15 12

Writing to Influx from Node-Red turned out to be a lot simpler than I thought it would be. Leading into the "Influx out" node is a "Change" node which sets msg.payload to a cross-walk like this:

{
    "voltage": msg.payload.v,
    "frequency": msg.payload.f,
    "current": msg.payload.a,
    "importEnergy": msg.payload.e,
    "meterErrors": msg.payload.eMask
}

The names on the left hand side are the field-keys I want in the Influx measurement. The values on the right hand side come straight from the MQTT message payload. A four-node flow gets the job done:

Screen Shot 2019-11-25 at 22 30 28

Logging away at 10-second intervals, day in, day out. Hardly any code to maintain. Just works. Those Node-Red people are brilliant.

Paraphraser avatar Nov 25 '19 11:11 Paraphraser

I do have an entry on the wiki on networking https://github.com/gcgarner/IOTstack/wiki/Networking

Everything used to be in the README which got a little hard to follow. I've added an additional link in the 'Getting started' section to direct people there

docker allows you two modes of networking, host mode and bridge mode. Depending on how you setup your python container it may be in --network host which allows it to use 127.0.0.1 . Normally you want the bridge mode because it allows you talk to the container by name. Additionally if you have two containers in host mode that both want to use port 80 one of them will fail. Bridge mode allows you to redirect the ports to avoid conflicts

gcgarner avatar Nov 25 '19 18:11 gcgarner