Hello,
I have a mqtt broker and want to send all the data to InfluxDB with Telegraf.
In the broker I have 2 types of data: json and value format.
If I configure one of them, it work. But if I configure both inputs I get this error:
2021-12-09T20:36:41Z E! [inputs.mqtt_consumer] Error in plugin: connection lost: EOF
2021-12-09T20:36:50Z E! [inputs.mqtt_consumer] Error in plugin: connection lost: EOF
2021-12-09T20:36:50Z I! [inputs.mqtt_consumer] Connected [tcp://myserver:1883]
2021-12-09T20:37:00Z E! [inputs.mqtt_consumer] Error in plugin: connection lost: EOF
2021-12-09T20:37:00Z I! [inputs.mqtt_consumer] Connected [tcp://myserver:1883]
2021-12-09T20:37:10Z E! [inputs.mqtt_consumer] Error in plugin: connection lost: EOF
[[inputs.mqtt_consumer]]
servers = ["tcp://myserver:1883"]
topics = [
"zigbee2mqtt/Sensor1",
"zigbee2mqtt/Sensor2",
"zigbee2mqtt/Sensor3"
]
client_id = "Telegraf"
username = "myuser"
password = "mypass"
data_format = "json"
[[inputs.mqtt_consumer]]
servers = ["tcp://myserver:1883"]
topics = ["shellies/shellyem-XXXXXXXXXXXX/emeter/0/power"]
client_id = "Telegraf"
username = "myuser"
password = "mypass"
data_format = "value"
data_type = "float"
Is there any other way to send both data?
Kind regards.
Hi @jlazkano,
This should work without incident I have tested the following on my end:
# Telegraf Configuration
#
# Telegraf is entirely plugin driven. All metrics are gathered from the
# declared inputs, and sent to the declared outputs.
#
# Plugins must be declared in here to be active.
# To deactivate a plugin, comment out the name and any variables.
#
# Use 'telegraf -config telegraf.conf -test' to see what metrics a config
# file would generate.
#
# Environment variables can be used anywhere in this config file, simply surround
# them with ${}. For strings the variable must be within quotes (ie, "${STR_VAR}"),
# for numbers and booleans they should be plain (ie, ${INT_VAR}, ${BOOL_VAR})
# Global tags can be specified here in key="value" format.
[global_tags]
# dc = "us-east-1" # will tag all metrics with dc=us-east-1
# rack = "1a"
## Environment variables can be used as tags, and throughout the config file
# user = "$USER"
# Configuration for telegraf agent
[agent]
## Default data collection interval for all inputs
interval = "5s"
## Rounds collection interval to 'interval'
## ie, if interval="10s" then always collect on :00, :10, :20, etc.
round_interval = true
## Telegraf will send metrics to outputs in batches of at most
## metric_batch_size metrics.
## This controls the size of writes that Telegraf sends to output plugins.
metric_batch_size = 1000
## Maximum number of unwritten metrics per output. Increasing this value
## allows for longer periods of output downtime without dropping metrics at the
## cost of higher maximum memory usage.
metric_buffer_limit = 10000
## Collection jitter is used to jitter the collection by a random amount.
## Each plugin will sleep for a random time within jitter before collecting.
## This can be used to avoid many plugins querying things like sysfs at the
## same time, which can have a measurable effect on the system.
collection_jitter = "5s"
## Default flushing interval for all outputs. Maximum flush_interval will be
## flush_interval + flush_jitter
flush_interval = "10s"
## Jitter the flush interval by a random amount. This is primarily to avoid
## large write spikes for users running a large number of telegraf instances.
## ie, a jitter of 5s and interval 10s means flushes will happen every 10-15s
flush_jitter = "5s"
## By default or when set to "0s", precision will be set to the same
## timestamp order as the collection interval, with the maximum being 1s.
## ie, when interval = "10s", precision will be "1s"
## when interval = "250ms", precision will be "1ms"
## Precision will NOT be used for service inputs. It is up to each individual
## service input to set the timestamp at the appropriate precision.
## Valid time units are "ns", "us" (or "µs"), "ms", "s".
precision = ""
## Override default hostname, if empty use os.Hostname()
hostname = ""
## If set to true, do no set the "host" tag in the telegraf agent.
omit_hostname = false
debug = true
quiet = false
###############################################################################
# OUTPUT PLUGINS #
###############################################################################
# Configuration for sending metrics to InfluxDB 2.0
[[outputs.influxdb_v2]]
alias = "mqtt"
## 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 = ["${INFLUX_HOST}"]
## Token for authentication.
token = "${INFLUX_TOKEN}"
## Organization is the name of the organization you wish to write to.
organization = "${INFLUX_ORG}"
## Destination bucket to write into.
bucket = "${INFLUX_BUCKET}"
###############################################################################
# INPUT PLUGINS #
###############################################################################
[[inputs.mqtt_consumer]]
alias = "consumer_1"
servers = ["tcp://192.168.1.220:1883"]
topics = [
"iotgateway",
]
data_format = "json_v2"
[[inputs.mqtt_consumer.json_v2]]
[[inputs.mqtt_consumer.json_v2.object]]
path = "@this"
tags = ["Factory", "Machine"]
[[inputs.mqtt_consumer]]
alias = "consumer_2"
servers = ["tcp://192.168.1.220:1883"]
topics = [
"value",
]
data_format = "value"
data_type = "float" # required
Just some things to check:
- what MQTT server are you using and what version?
- What version of telegraf?
- Is there any security parameters in the MQTT server config which could prevent a second connection?
- Have you tried defining different client ID’s for each?
EOF normally indicates a security issue in other plugins.
Hello,
I got it!
I need to change the client_id for each mqtt input.
client_id = "TelegrafShelly"
client_id = "TelegrafZigbee2MQTT"
Regards.
1 Like