I am trying to have two separates docker instances:
- MQTT broker (toke/mosquitto): listens to ESP32 chips.
- Telegraf: subscribes to the MQTT broker.
Here are both configuration files:
MQTT broker config
# following two lines required for > v2.0
allow_anonymous true
listener 1883
persistence true
persistence_location /mosquitto/data/
connection_messages true
log_timestamp true
log_dest file /mosquitto/log/mosquitto.log
Telegraf conig
[[outputs.influxdb]]
database = "tlgDB"
precision = "s"
retention_policy = ""
write_consistency = "any"
urls = [ "http://localhost:8086" ]
skip_database_creation = true
username = "tlg_username"
password = "tlg_password"
# ...
[[inputs.mqtt_consumer]]
servers = ["tcp://localhost:1883"]
name_override = "canary"
topics = ["canary/#"]
topic_tag = "topic"
data_format = "json"
docker-compose file
services:
telegraf:
image: telegraf:1.17
volumes:
- /data/telegraf:/inputs/logs
- /data/telegraf:/var/log/telegraf
configs:
- source: telegraf-conf
target: /etc/telegraf/telegraf.conf
toke-mosquitto-docker:
image: toke-mosquitto-docker:latest # the configuration file in embedded in the image
ports:
- 1883
volumes:
- mosquitto-data:/mqtt/data
volumes:
mosquitto-data:
The problem: Neither canary nor mqtt_consumer are available in influxdb, and the only log I can get from Telegraf is: [inputs.mqtt_consumer] Connecting [tcp://localhost:1883].
I checked the MQTT broker by subscribing using mosquitto_sub and it works fine.
I strongly suspect a network error between the docker instances.