Cannot connect to Influx datasource from Grafana

Hello, I’ve been trying to create myself a raspberry pi temperature sensor and with some of the excellent articles out there, I’ve got to the point where it seems I am nearly complete.

I have been following this guide: GitHub - WesleyCharlesBlake/raspberry-pi-temperature: OneWire temp logger on RPI, with a remote Grafana and InfluxDB stack deployed with Docker

I have created my Ubuntu server VM, installed Docker and ran the following commands to get the containers created, but for some reason, I cannot get Grafana to connect to InfluxDB.

My settings are as follows:

InfluxDB details: Database: dbname user: user password: pass

Now, my Raspberry Pi is running the python script and outputting a temperature. I have configured the Pi script with the following:

  • influx_host = ‘10.16.61.59’
  • host = ‘grafana’
  • port = 8086
  • dbname = ‘dbname’
  • user = ‘user’
  • password = ‘pass’
  • temp_sensor = ‘/sys/bus/w1/devices/28-0113136957aa/w1_slave’

Whenever I try to Save and Test the datasource, I am getting:

*Network Error: Bad Gateway (502)

I’ve done a bit of searching and can’t seem to identify why it will not connect to the InfluxDB.

When I try to save and Test, I get this output from my Docker VM:

grafana_1 | 2019/01/07 20:29:39 http: proxy error: dial tcp 127.0.0.1:8086: connect: connection refused grafana_1 | t=2019-01-07T20:29:39+0000 lvl=info msg=“Request Completed” logger=context userId=1 orgId=1 uname=admin method=GET path=/api/datasources/proxy/1/query status=502 remote_addr=10.16.12.21 time_ms=15 size=0 referer=http://10.16.61.59:3000/datasources/edit/1

It seems that Influx is refusing my connection?

Does anybody know what may be wrong?

Thank you

Hi,

As you are using Docker containers for your setup, you need to be aware how the networking stack works with Docker Compose.

  influx:
    image: influxdb
    ports:
     - "8083:8083"
     - "8086:8086"

With the above, your InfluxDB service is publishing ports to the host. This means your logger.py script can connect to InfluxDB on localhost:8086.

As Grafana runs as a container inside of the Docker networking stack, Grafana should be configured to speak to InfluxDB using the http://influx:8086 (when using “Access: Server”) or localhost when using “Access: Client”.

When using server access, you use influx as the hostname because that is what your service is called within the docker-compose.yml file.

3 Likes

i had same issue. using container name instead of local host solved my problem

Hi @Hasan_Hassu welcome and thank you for your feedback :slight_smile:

Hi, I am facing same issue, influxdb_V2 and Grafana on docker (synology nas), but cannot succeed to connect Grafana to influxdb, have tried all combination of Query Language (InfluxQL & Influx), even replaced the bucket name by bucket ID still having error message “Failed to fetch”. Could you please advise? Thanks

Definitive guide for configuring InfluxDB v2 OSS with Grafana: Use Grafana with InfluxDB OSS | InfluxDB OSS 2.0 Documentation