4

I am trying to set up a Telegraf and Influxdb on macOS 11.3.1 using docker compose. But unfortunately, I am getting the following error:

telegraf     | 2021-07-12T19:18:14Z E! [outputs.influxdb_v2] When writing to [http://localhost:8086]: Post "http://localhost:8086/api/v2/write?bucket=telegraf&org=telegraf": dial tcp 127.0.0.1:8086: connect: connection refused
telegraf     | 2021-07-12T19:18:14Z E! [agent] Error writing to outputs.influxdb_v2: Post "http://localhost:8086/api/v2/write?bucket=telegraf&org=telegraf": dial tcp 127.0.0.1:8086: connect: connection refused

Here are my config files:

docker-compose.yml

version: "3.5"

services:
  influxdb2:
    image: influxdb:latest
    network_mode: "bridge"
    container_name: influxdb2
    ports:
      - "8086:8086"
    volumes:
      - type: bind
        source: /Users/endryha/Docker/influxdb2/data
        target: /var/lib/influxdb2
      - type: bind
        source: /Users/endryha/Docker/influxdb2/config
        target: /etc/influxdb2
    environment:
      - DOCKER_INFLUXDB_INIT_MODE=setup
      - DOCKER_INFLUXDB_INIT_USERNAME=telegraf
      - DOCKER_INFLUXDB_INIT_PASSWORD=P@ssw0rd
      - DOCKER_INFLUXDB_INIT_ORG=telegraf
      - DOCKER_INFLUXDB_INIT_BUCKET=telegraf
      - DOCKER_INFLUXDB_INIT_RETENTION=1w
      - DOCKER_INFLUXDB_INIT_ADMIN_TOKEN=9859DAA6-3B3F-48FE-A981-AE9D31FBB334
    restart: always
  telegraf:
    image: telegraf:latest
    network_mode: "bridge"
    pid: "host"
    container_name: telegraf
    ports:
      - "8092:8092"
      - "8094:8094"
      - "8125:8125"
    volumes:
      - ./telegraf.conf:/etc/telegraf/telegraf.conf:ro
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - /sys:/host/sys:ro
      - /proc:/host/proc:ro
      - /etc:/host/etc:ro
    environment:
      - HOST_PROC=/host/proc
      - HOST_SYS=/host/sys
      - HOST_ETC=/host/etc
    restart: always

telegraf.conf

# # Configuration for sending metrics to InfluxDB
 [[outputs.influxdb_v2]]
#   ## The URLs of the InfluxDB cluster nodes.
#   ##
#   ## Multiple URLs can be specified for a single cluster, only ONE of the
#   ## urls will be written to each interval.
#   ##   ex: urls = ["https://us-west-2-1.aws.cloud2.influxdata.com"]
  urls = ["http://localhost:8086"]
#
#   ## Token for authentication.
  token = "9859DAA6-3B3F-48FE-A981-AE9D31FBB334"
  # token = "sYbrP0VZ--MgCd0EpOpz9OctJN2e4kUbsfbPPUGcY9GYW8Ts27W2cI_d7YwlSf9nvHq4l-K6mJLqJiTT0Hh7Xw=="
#
#   ## Organization is the name of the organization you wish to write to; must exist.
  organization = "telegraf"
#
#   ## Destination bucket to write into.
  bucket = "telegraf"
#
#   ## The value of this tag will be used to determine the bucket.  If this
#   ## tag is not set the 'bucket' option is used as the default.
#   # bucket_tag = ""
#
#   ## If true, the bucket tag will not be added to the metric.
#   # exclude_bucket_tag = false
#
#   ## Timeout for HTTP messages.
#   # timeout = "5s"
#
#   ## Additional HTTP headers
#   # http_headers = {"X-Special-Header" = "Special-Value"}
#
#   ## HTTP Proxy override, if unset values the standard proxy environment
#   ## variables are consulted to determine which proxy, if any, should be used.
#   # http_proxy = "http://corporate.proxy:3128"
#
#   ## HTTP User-Agent
  user_agent = "telegraf"
#
#   ## Content-Encoding for write request body, can be set to "gzip" to
#   ## compress body or "identity" to apply no encoding.
#   # content_encoding = "gzip"
#
#   ## Enable or disable uint support for writing uints influxdb 2.0.
#   # influx_uint_support = false
#
#   ## Optional TLS Config for use on HTTP connections.
#   # tls_ca = "/etc/telegraf/ca.pem"
#   # tls_cert = "/etc/telegraf/cert.pem"
#   # tls_key = "/etc/telegraf/key.pem"
#   ## Use TLS but skip chain & host verification
#   # insecure_skip_verify = false

Full log output

docker-compose up
Starting telegraf  ... done
Starting influxdb2 ... done
Attaching to influxdb2, telegraf
telegraf     | 2021-07-12T19:18:04Z I! Starting Telegraf 1.19.1
telegraf     | 2021-07-12T19:18:04Z I! Using config file: /etc/telegraf/telegraf.conf
telegraf     | 2021-07-12T19:18:04Z I! Loaded inputs: cpu disk diskio docker kernel mem processes swap system
telegraf     | 2021-07-12T19:18:04Z I! Loaded aggregators:
telegraf     | 2021-07-12T19:18:04Z I! Loaded processors:
telegraf     | 2021-07-12T19:18:04Z I! Loaded outputs: influxdb_v2
telegraf     | 2021-07-12T19:18:04Z I! Tags enabled: host=d52a95d7ec9d
telegraf     | 2021-07-12T19:18:04Z I! [agent] Config: Interval:10s, Quiet:false, Hostname:"d52a95d7ec9d", Flush Interval:10s
telegraf     | 2021-07-12T19:18:04Z W! [inputs.docker] 'perdevice' setting is set to 'true' so 'blkio' and 'network' metrics will be collected. Please set it to 'false' and use 'perdevice_include' instead to control this behaviour as 'perdevice' will be deprecated
telegraf     | 2021-07-12T19:18:04Z W! [inputs.docker] 'total' setting is set to 'false' so 'blkio' and 'network' metrics will not be collected. Please set it to 'true' and use 'total_include' instead to control this behaviour as 'total' will be deprecated
influxdb2    | 2021-07-12T19:18:04.687801589Z   info    found existing boltdb file, skipping setup wrapper  {"system": "docker", "bolt_path": "/var/lib/influxdb2/influxd.bolt"}
influxdb2    | ts=2021-07-12T19:18:11.025589Z lvl=info msg="Welcome to InfluxDB" log_id=0VJ2KiKG000 version=2.0.7 commit=2a45f0c037 build_date=2021-06-04T19:17:40Z
influxdb2    | ts=2021-07-12T19:18:11.029935Z lvl=info msg="Resources opened" log_id=0VJ2KiKG000 service=bolt path=/var/lib/influxdb2/influxd.bolt
influxdb2    | ts=2021-07-12T19:18:11.036551Z lvl=info msg="Checking InfluxDB metadata for prior version." log_id=0VJ2KiKG000 bolt_path=/var/lib/influxdb2/influxd.bolt
influxdb2    | ts=2021-07-12T19:18:11.037662Z lvl=info msg="Using data dir" log_id=0VJ2KiKG000 service=storage-engine service=store path=/var/lib/influxdb2/engine/data
influxdb2    | ts=2021-07-12T19:18:11.037699Z lvl=info msg="Compaction settings" log_id=0VJ2KiKG000 service=storage-engine service=store max_concurrent_compactions=4 throughput_bytes_per_second=50331648 throughput_bytes_per_second_burst=50331648
influxdb2    | ts=2021-07-12T19:18:11.037705Z lvl=info msg="Open store (start)" log_id=0VJ2KiKG000 service=storage-engine service=store op_name=tsdb_open op_event=start
influxdb2    | ts=2021-07-12T19:18:11.037820Z lvl=info msg="Open store (end)" log_id=0VJ2KiKG000 service=storage-engine service=store op_name=tsdb_open op_event=end op_elapsed=0.116ms
influxdb2    | ts=2021-07-12T19:18:11.037863Z lvl=info msg="Starting retention policy enforcement service" log_id=0VJ2KiKG000 service=retention check_interval=30m
influxdb2    | ts=2021-07-12T19:18:11.037873Z lvl=info msg="Starting precreation service" log_id=0VJ2KiKG000 service=shard-precreation check_interval=10m advance_period=30m
influxdb2    | ts=2021-07-12T19:18:11.037900Z lvl=info msg="Starting query controller" log_id=0VJ2KiKG000 service=storage-reads concurrency_quota=1024 initial_memory_bytes_quota_per_query=9223372036854775807 memory_bytes_quota_per_query=9223372036854775807 max_memory_bytes=0 queue_size=1024
influxdb2    | ts=2021-07-12T19:18:11.038758Z lvl=info msg="Configuring InfluxQL statement executor (zeros indicate unlimited)." log_id=0VJ2KiKG000 max_select_point=0 max_select_series=0 max_select_buckets=0
influxdb2    | ts=2021-07-12T19:18:11.331457Z lvl=info msg=Listening log_id=0VJ2KiKG000 service=tcp-listener transport=http addr=:8086 port=8086
influxdb2    | ts=2021-07-12T19:18:11.331525Z lvl=info msg=Starting log_id=0VJ2KiKG000 service=telemetry interval=8h
telegraf     | 2021-07-12T19:18:14Z E! [outputs.influxdb_v2] When writing to [http://localhost:8086]: Post "http://localhost:8086/api/v2/write?bucket=telegraf&org=telegraf": dial tcp 127.0.0.1:8086: connect: connection refused
telegraf     | 2021-07-12T19:18:14Z E! [agent] Error writing to outputs.influxdb_v2: Post "http://localhost:8086/api/v2/write?bucket=telegraf&org=telegraf": dial tcp 127.0.0.1:8086: connect: connection refused
telegraf     | 2021-07-12T19:18:24Z E! [outputs.influxdb_v2] When writing to [http://localhost:8086]: Post "http://localhost:8086/api/v2/write?bucket=telegraf&org=telegraf": dial tcp 127.0.0.1:8086: connect: connection refused
telegraf     | 2021-07-12T19:18:24Z E! [agent] Error writing to outputs.influxdb_v2: Post "http://localhost:8086/api/v2/write?bucket=telegraf&org=telegraf": dial tcp 127.0.0.1:8086: connect: connection refused
telegraf     | 2021-07-12T19:18:34Z E! [outputs.influxdb_v2] When writing to [http://localhost:8086]: Post "http://localhost:8086/api/v2/write?bucket=telegraf&org=telegraf": dial tcp 127.0.0.1:8086: connect: connection refused

As I can see there is an issue with the authorization, however, I think that I correctly provided the token and it suppose to work just fine. Also, I've tried to create a token manually using InfluxDB admin UI, but, it doesn't work as well.

Please advice.

endryha
  • 7,166
  • 8
  • 40
  • 64
  • 10
    In the telegraf.conf you have a configuration line `urls = ["http://localhost:8086"]`, I assume that this is the pointer to another container, running influxdb. In this case, this should probably be `urls = ["http://influxdb2:8086"]`. – jabbson Jul 12 '21 at 20:28
  • No, this is not the issue, if I change it to http://influxdb2:8086 then I get the following error: telegraf | 2021-07-13T09:51:04Z E! [outputs.influxdb_v2] When writing to [http://influxdb2:8086]: Post "http://influxdb2:8086/api/v2/write?bucket=telegraf&org=telegraf": dial tcp: lookup influxdb2 on 192.168.65.5:53: no such host telegraf | 2021-07-13T09:51:04Z E! [agent] Error writing to outputs.influxdb_v2: Post "http://influxdb2:8086/api/v2/write?bucket=telegraf&org=telegraf": dial tcp: lookup influxdb2 on 192.168.65.5:53: no such host – endryha Jul 13 '21 at 09:51
  • 2
    the fact that you get another error absolutely doesn't mean that your initial issue isn't an issue, instead that means your config has several. Clearly the service discovery through dns resolution isn't working. My bet is - this is due to using `network_mode: "bridge"`, which makes docker to use the default network (which doesn't run service discovery). Unless there is a very good reason to have it in there, delete this line for both containers, the network will be created automatically. – jabbson Jul 13 '21 at 11:38
  • thank you for the explanation, I will try this out – endryha Jul 13 '21 at 12:58
  • 1
    @endryha have you been succesful? seeing the same issue having `urls = ["http://influxdb2:8086"]` configured. – mcnesium Oct 19 '21 at 16:20

0 Answers0