Skip to content

Telegraf MQTT input exits if Broker is not available on startup #3167

@asciijungle

Description

@asciijungle

Bug report

Relevant telegraf.conf:

 [[inputs.mqtt_consumer]]
  servers = ["192.168.178.46:1883"]
  ## MQTT QoS, must be 0, 1, or 2
  qos = 0

  ## Topics to subscribe to
  topics = [
    "/home/+/metrics"
  ]
  persistent_session = false
  # If empty, a random client ID will be generated.
  client_id = ""
  data_format = "influx"

[[outputs.influxdb]]
  ## The full HTTP or UDP endpoint URL for your InfluxDB instance.
  ## Multiple urls can be specified as part of the same cluster,
  ## this means that only ONE of the urls will be written to each interval.
  # urls = ["udp://localhost:8089"] # UDP endpoint example
  urls = ["http://influxdb:8086"] # required
  ## The target database for metrics (telegraf will create it if not exists).
  database = "home" # required

  ## Retention policy to write to. Empty string writes to the default rp.
  retention_policy = ""
  ## Write consistency (clusters only), can be: "any", "one", "quorum", "all"
  write_consistency = "any"

  ## Write timeout (for the InfluxDB client), formatted as a string.
  ## If not provided, will default to 5s. 0s means no timeout (not recommended).
  timeout = "30s"

System info:

latest docker container pulled from docker hub.

Steps to reproduce:

docker run -v "$(pwd)/telegraf.conf:/etc/telegraf/telegraf.conf:ro" telegraf:latest

Expected behavior:

telegraf tries to reconnect until it reaches a configurable timeout.

Actual behavior:

telegraf exists after a couple of seconds. This is not enough time for a mqtt broker to start up in a docker-compose scenario. The timeout can not be extended by the configuration defined in mqtt_consumer.go
I believe there is only one connection attempt being made. I'd like to be able to start my whole stack consisting of influxdb, telegraf, the mqtt broker and grafana to be launched in a single docker-compose stack. As of now this is unfortunately not possible.

Additional info:

% docker run -it -v "$(pwd)/telegraf.conf:/etc/telegraf/telegraf.conf:ro" telegraf:latest                                                          
2017/08/24 12:26:31 I! Using config file: /etc/telegraf/telegraf.conf
2017-08-24T12:26:37Z I! Database creation failed: Post http://influxdb:8086/query?q=CREATE+DATABASE+%22home%22: dial tcp: lookup influxdb on 192.168.3.9:53: server misbehaving
2017-08-24T12:26:37Z I! Starting Telegraf (version 1.3.5)
2017-08-24T12:26:37Z I! Loaded outputs: influxdb
2017-08-24T12:26:37Z I! Loaded inputs: inputs.mqtt_consumer
2017-08-24T12:26:37Z I! Tags enabled: host=639a81d8ad20
2017-08-24T12:26:37Z I! Agent Config: Interval:10s, Quiet:false, Hostname:"639a81d8ad20", Flush Interval:10s 
2017-08-24T12:27:07Z E! Service for input inputs.mqtt_consumer failed to start, exiting
Network Error : dial tcp 192.168.178.46:1883: i/o timeout

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugunexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions