How can I load mqtt data to influxdb?

I want to put the message sent from mqtt into influxdb.
I connected influxdb, telegraf, and mosquitto in docker.

When you publish a message to topic “test2”, it is written to the telegraf log.

mqtt_consumer,host=538b7977801d,topic=test2 value="test2 hi" 1639551391139366583

What should I do to see this result in influxdb?


  ## Default data collection interval for all inputs
  interval = "10s"
  round_interval = true
  metric_batch_size = 1000
  metric_buffer_limit = 10000
  collection_jitter = "0s"
  flush_interval = "10s"
  flush_jitter = "0s"
  precision = ""
  hostname = "" 
   urls = ["http://influx:8086"]
   token = "my token"
   organization = "admin_org"
   namepass = ["test_bucket"]
   bucket = "test_bucket"

  files = ["stdout", "/tmp/metrics.out"]

  servers = ["tcp://mosquitto:1883"]
  topics = [
  qos = 0
  connection_timeout = "30s"
  client_id = "telegraf"
  persistent_session = false
  data_format = "value"
  data_type = "string"

Hi @Jeong925,
Are you seeing any connection errors between Telegraf and InfluxDB?
Perhaps you could run your Telegraf config using:

telegraf --debug --config <pathtoconfig>

This should give us more logs to understand.

Hi :blush:

2021-12-20T02:44:41Z I! Starting Telegraf 1.20.4
2021-12-20T02:44:41Z I! Using config file: /etc/telegraf/telegraf.conf
2021-12-20T02:44:41Z I! Loaded inputs: mqtt_consumer
2021-12-20T02:44:41Z I! Loaded aggregators: 
2021-12-20T02:44:41Z I! Loaded processors: 
2021-12-20T02:44:41Z I! Loaded outputs: file influxdb_v2
2021-12-20T02:44:41Z I! Tags enabled: host=538b7977801d
2021-12-20T02:44:41Z I! [agent] Config: Interval:10s, Quiet:false, Hostname:"538b7977801d", Flush Interval:10s
2021-12-20T02:44:41Z I! [inputs.mqtt_consumer] Connected [tcp://mosquitto:1883]

I think it’s working normally.
I wonder how to put the topic and message sent through the mosquitto broker in the influxDB and check it.

Hi @Jeong925,
Sorry, you caught me just before I went on holiday. Interesting so it looks to be connecting your broker fine. At the moment you are using # to wild card the topics you are pulling from. Could you try and specify the actual topic and we will see if that is the problem.