0

I am trying to integrate grafana and influxdb to get some metrics. But not sure when I am trying to test it, authentication to data source is failing. Please help me out with this issue.

Here is the below yaml and conf file.

Docker-compose file

version: "3"
services:
  grafana:
    image: grafana/grafana
    container_name: grafana
    restart: always
    ports:
      - 3000:3000
    networks:
      - monitoring
    volumes:
      - grafana-volume:/vol01/Docker/monitoring
    environment:
      - GF_LOG_LEVEL=debug
      - GF_DATAPROXY_LOGGING=true
      - GF_DATAPROXY_TIMEOUT=60

  influxdb:
    image: influxdb
    container_name: influxdb
    restart: always
    ports:
      - 8086:8086
    networks:
      - monitoring
    volumes:
      - influxdb-volume:/vol01/Docker/monitoring
    environment:
      - INFLUXDB_DB=telegraf
      - INFLUXDB_USER=telegraf
      - INFLUXDB_ADMIN_ENABLED=true
      - INFLUXDB_HTTP_AUTH_ENABLED=false
      - INFLUXDB_ADMIN_USER=admin
      - INFLUXDB_ADMIN_PASSWORD=Welcome1
      - GF_LOG_LEVEL=debug
      - GF_DATAPROXY_LOGGING=true

  telegraf:
    image: telegraf
    container_name: telegraf
    restart: always
    extra_hosts:
     - "influxdb:18.216.224.127"
    environment:
      ST_PROC: /rootfs/proc
      HOST_SYS: /rootfs/sys
      HOST_ETC: /rootfs/etc


    volumes:
     - ./telegraf.conf:/etc/telegraf/telegraf.conf:ro
     - /var/run/docker.sock:/var/run/docker.sock:ro
     - /sys:/rootfs/sys:ro
     - /proc:/rootfs/proc:ro
     - /etc:/rootfs/etc:ro
networks:
  monitoring:
volumes:
  grafana-volume:

Conf file

[global_tags]

[agent]
  interval = "60s"
  round_interval = true
  metric_batch_size = 1000
  metric_buffer_limit = 10000
  collection_jitter = "0s"
  flush_interval = "10s"
  flush_jitter = "0s"
  precision = ""
  hostname = "18.216.224.127"
  omit_hostname = false

[[outputs.influxdb]]
urls = ["http://18.216.224.127:8086"]
database = "telegraf"
timeout = "5s"
username = "telegraf"
password = "Welcome1"


[[inputs.ping]]
interval = "5s"
urls = ["192.168.0.44", "192.168.0.131", "192.168.0.130", "google.com", "amazon.com", "github.com"]
count = 4
ping_interval = 1.0
timeout = 2.0


[[inputs.cpu]]
  percpu = true
  totalcpu = true
  collect_cpu_time = false
  report_active = false


[[inputs.disk]]
  ignore_fs = ["tmpfs", "devtmpfs", "devfs", "iso9660", "overlay", "aufs", "squashfs"]

[[inputs.diskio]]

[[inputs.kernel]]

[[inputs.mem]]

[[inputs.processes]]

[[inputs.swap]]

[[inputs.system]]
                                                                                                                                                                                             

ERROR

t=2021-05-08T11:02:29+0000 lvl=info msg="Authentication to data source failed" logger=data-proxy-log userId=1 orgId=1 uname=admin path=/api/datasources/proxy/1/query remote_addr=108.237.178.97 referer=http://18.216.224.127:3000/datasources/edit/1/ body="{"code":"unauthorized","message":"Unauthorized"}" statusCode=401 t=2

1
  • 1
    Did you figure this out? I'm having a similar issue. Commented Jul 28, 2021 at 20:42

2 Answers 2

4

Had the same issue when using InfluxQL language. Using Flux fixed the problem. Since the latest influxdb images - 2.x, use a slightly different set of envvars, you'll have to change them. According to https://github.com/docker-library/docs/blob/master/influxdb/README.md#automated-setup, you need to change existing envvars to:

  • DOCKER_INFLUXDB_INIT_USERNAME
  • DOCKER_INFLUXDB_INIT_PASSWORD
  • DOCKER_INFLUXDB_INIT_ORG
  • etc

And also to use Flux you have to add DOCKER_INFLUXDB_INIT_ADMIN_TOKEN envvar. Here is an example of docker-compose part of the "influxdb" service:

environment:
  - INFLUXDB_DB=telegraf
  - DOCKER_INFLUXDB_INIT_MODE=setup
  - DOCKER_INFLUXDB_INIT_USERNAME=admin
  - DOCKER_INFLUXDB_INIT_PASSWORD=Welcome1
  - DOCKER_INFLUXDB_INIT_ORG=telegraf_org
  - DOCKER_INFLUXDB_INIT_BUCKET=telegraf_bucket
  - DOCKER_INFLUXDB_INIT_ADMIN_TOKEN=admin_token

In the Grafana UI:

  • change InfluxQL to Flux
  • put *_ORG, *_BUCKET, and *_ADMIN_TOKEN envvars values into according inputs of "InfluxDB Details" section
Sign up to request clarification or add additional context in comments.

Comments

0

If you have the Grafana UI set up, you can test this from your browser at /datasources. Here you can find your data source. If you click "Save & test" it will tell you whether it was able to find buckets. If it can't, you may have wrong url, credentials or auth settings configured.

For me, the problem was that after I reset my influxdb deployment, credentials had changed and I needed to update this in the datasource config. This method allowed me to quickly check my configuration before committing any configuration (I use helm).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.