IMD SolutionComputing LibraryShop main store

Troubleshooting

Why Telegraf MQTT consumer writes nothing to InfluxDB Cloud

Edge computing and IIoT Published 7 min read

Short answer

Nothing reaches the bucket because three faults act at once: the broker URL on port 8883 has no ssl:// scheme, so the consumer never subscribes; the published payload is not valid line protocol, so the parser rejects it; and the token variable expands empty inside the service, so writes return HTTP 401. Fix all three, delete tag_keys for the influx data format, and give each Telegraf instance its own client_id.

On this page
  1. Where the data stops on the way to the bucket
  2. The broker URL needs the ssl:// scheme
  3. Worked example: parsing sensors, sensor1=counter value=0, sensor2=counter2 value=5
  4. The token variable is empty inside the service
  5. tag_keys does nothing for the influx data format
  6. One client_id per Telegraf instance
  7. Finding the Telegraf logs
  8. Proving each hop in order
  9. Which fault explains which symptom
  10. Questions asked

Three independent faults stop this pipeline, and any one of them is enough to leave the bucket in InfluxDB Cloud empty. The servers entry for the cloud broker carries no ssl:// scheme, so the consumer never negotiates TLS and never subscribes. The published payload is not valid line protocol, so the influx parser rejects every message. And the token is read from an environment variable that a service does not inherit, so every write comes back unauthorized. Behind those sit two smaller ones: tag_keys, which does nothing for the influx data format, and a client_id built from the username, which two Telegraf instances would share. None of this is visible in the cloud console, because no write is ever attempted; the evidence lives in the Telegraf log on the host that runs Telegraf.

Where the data stops on the way to the bucket #

Telegraf is the only moving part you own here. InfluxDB Cloud gives you the bucket and its write endpoint, not a machine, so there is nothing to inspect on the cloud side until a write actually arrives. That makes the order of the hops the order of the diagnosis:

  • Connection: the consumer opens TLS to the cloud broker on the port in the servers entry and subscribes to my/test/topic. A missing scheme or a rejected credential pair stops everything here, and the log shows little or nothing.
  • Parsing: each message is read as Influx line protocol. A malformed payload is dropped with a parsing failure, and nothing reaches the output.
  • Write: the output posts each batch to the cloud URL. Only here do cloud-visible symptoms appear: unauthorized writes, a wrong organization or a missing bucket.

A fault at the first two hops leaves an empty bucket with no cloud-side clue at all, which is why the Telegraf log, not the cloud console, is the first place to look. The same symptom against a broker inside the plant network is worked through separately in Telegraf MQTT consumer connects but writes no data to InfluxDB.

The broker URL needs the ssl:// scheme #

The servers entries are URLs, and the scheme tells the client which transport to speak. The plugin reference shows the form ssl://localhost:1883: scheme first, then host, then port. A bare host and port give the client no TLS transport, and against a TLS-only port the failure can be completely silent — a plugin issue report describes attempts against such a port where nothing occurs and no error is printed. The consumer therefore never subscribes, and every later hop looks healthy because nothing ever reaches it.

The correction is one line, with the host string taken from your broker's cluster page:

[[inputs.mqtt_consumer]]
  servers = ["ssl://your-cluster-host:8883"]
  topics = ["my/test/topic"]

When the address itself is wrong rather than the scheme — a localhost address inside a container, for example — the silence is the same, and that variant has its own article: Fix Telegraf MQTT connecting to localhost in Docker.

Worked example: parsing sensors, sensor1=counter value=0, sensor2=counter2 value=5 #

Inputs: the payload exactly as the publish test sends it — sensors, sensor1=counter value=0, sensor2=counter2 value=5 — and the rule the influx parser applies: Influx line protocol, one point per line, written as measurement, then a comma and the tag set with no space between them, then one space, then the field set, then optionally one more space and a timestamp.

Count through the payload:

  • The comma at character 8 ends the measurement sensors. Character 9 is a space, immediately after that comma, so the first tag key is empty. Defect one.
  • The line carries four spaces in total, at characters 9, 25, 34 and 51. Past the measurement, a valid line of this shape may hold exactly two: the one that ends the tag set, and the optional one that starts the timestamp. The other two push pieces of the field set into timestamp position, and a timestamp must be an integer epoch value. Defect two.
  • Four spaces minus the two allowed is two too many, and either defect alone fails the line.

Result: the parser rejects the message, logs a parsing failure for the topic, and builds no metric, so the write hop never sees data from this publisher.

Decision: the comma after the measurement must run straight into a tag key, and the field set must hold no space at all; this payload satisfies neither, so every such message is dropped. The same two sensors go over as two points on two lines, in one message:

sensors,sensor1=counter value=0
sensors,sensor2=counter2 value=5

or as one point per publish:

mosquitto_pub -h your-cluster-host -p 8883 -u brokeruser -P brokerpass -t my/test/topic -m 'sensors,sensor1=counter value=0'

The token variable is empty inside the service #

token = "$INFLUX_TOKEN" asks Telegraf to substitute the variable from the environment of its own process when the config loads. A foreground run in your shell inherits your exports; a service started by the init system on Linux, or by the Windows service manager, inherits the service environment instead, and the variable is not there. The substitution then yields an empty token, and the cloud rejects the write as unauthorized — HTTP 401 in the log.

Fix it where the service reads its environment: on Linux, an environment file that the unit loads; on Windows, the environment configured for that service. Then restart the service, so the config loads again with the value present. Pasting the token into the config also works, but a credential in a config file leaks through backups and screenshots; keep it in the environment, and rotate any credential that has appeared in a public post.

tag_keys does nothing for the influx data format #

tag_keys belongs to the JSON-side parsers, where it promotes listed fields to tags. With data_format = "influx", the tags come from the line protocol itself — in the corrected payload, sensor1=counter is already a tag — so the entry has no effect and only misleads the next reader. Delete it. Keep topic_tag, which stamps each message's topic into a tag regardless of data format. If the payload later moves to JSON, field mapping becomes real work, and Turn an MQTT topic into InfluxDB fields with Telegraf walks that mapping.

One client_id per Telegraf instance #

Three faults share this setting. The client_id duplicates the username, which is legal but invites the second fault: with persistent_session = true the broker binds the session to that ID, and a second Telegraf instance — a test run in a terminal while the service also runs — connecting with the same ID makes the broker drop the older connection, so the two kick each other off in a repeating cycle. Third, the credential pair in the config is not the pair the publish test used, so a successful test publish proves nothing about the credentials Telegraf itself presents.

Decision: give every running instance its own client_id, set persistent_session = true only where a session must survive a reconnect, and test credentials with the same pair the config carries.

Finding the Telegraf logs #

Where the log lives depends on how Telegraf was started, not on anything in the cloud:

  • Foreground run: the terminal itself.
  • Linux service: journalctl -u telegraf.
  • Windows service: the Windows event log, or a file if one is set in the config.
  • Any start method: set debug = true in the [agent] section and add a file output while diagnosing:
[agent]
  debug = true

[[outputs.file]]
  files = ["stdout"]

With that output in place, every parsed metric prints as line protocol, so a connection fault and a parsing fault can no longer hide behind each other. Remove debug and the file output once the pipeline works: debug logging at message rate fills a gateway's disk.

Proving each hop in order #

  1. Correct the servers entry, restart, and confirm in the log a successful broker connection and the subscription to my/test/topic.
  2. Publish the corrected two-line payload with the debug output still in place: the parsed points print as line protocol. A parsing failure printed instead means the payload is still malformed.
  3. Move the token variable into the service environment, restart, and read the write result: HTTP 401 means the token arrived empty or wrong, HTTP 403 means it is valid but lacks write permission on the bucket, HTTP 404 means the organization or bucket name does not match the account.
  4. Open Data Explorer in the cloud console, select bucket MQTT_sensor_data, measurement sensors, and confirm the sensor1 and sensor2 tag values, their value fields, and the topic tag.

Which fault explains which symptom #

  • No connection attempt in the log and no error while the broker host is reachable: the scheme fault. Add ssl:// to the servers entry.
  • A parsing failure logged for the topic and nothing printed on stdout: the payload fault. One point per line, comma tight to the measurement, two spaces at most.
  • A clean parse and writes answered with HTTP 401: the token fault. Put the variable in the service environment and restart.
  • A client that connects and is dropped over and over: the client_id fault. One ID per instance.
  • tag_keys still in the file while everything else works: no symptom and no effect — delete it anyway.

Fix all of them in one pass. Each is a one-line change, and the debug output plus the service log split the pipeline into hops you can watch separately.

Questions asked

Does Telegraf run inside InfluxDB Cloud?

No. The cloud service supplies the database and its HTTP write endpoint, not a machine you can log into, so there is no place to install or start Telegraf there. Telegraf runs on hardware you control — an edge gateway, an industrial mini PC or a virtual machine — and pushes to the cloud URL from there. Your config, logs and environment variables all live on that host, which is why the token and the broker URL are fixed there rather than in the cloud console.

Why does the token still arrive empty after I export it in my shell?

Telegraf substitutes variables once, when it loads the config inside its own process. A service started by the init system or the Windows service manager inherits the service environment, not your shell session. You can prove it: run Telegraf in the foreground of a shell with the variable exported — if that run writes while the service on the same host returns HTTP 401, the missing service environment is confirmed. Define the variable where the service reads its environment and restart the service.

Can one MQTT message carry both sensors?

Yes, as two points on two lines inside one payload, separated by a newline. What one line cannot carry is two sensors joined by a comma: a comma inside the field set starts another field of the same point, and the fields of one point must share the measurement and the tag set. Publishing one point per message also works and is the simplest shape to debug.

The subscription asks for qos 2 — why do messages still arrive at most once?

Delivery quality is capped by the lower of the publisher's level and the subscriber's granted level. A publish sent at quality of service 0 is delivered at 0 even though the consumer subscribes at 2, so nothing is redelivered if the connection drops. To get the behavior the config promises, the publishing client has to publish at quality of service 2 as well.

Why are new points for a field rejected after some points were already written?

Fields are typed. The notation value=0 writes a float field, and value=0i writes an integer field, and a series keeps one type per field: a write that arrives with the other type is rejected. Choose the notation once for each field — integers for counters, floats for measured values — and publish every point with it.

Keep reading

  • Troubleshooting

    Fix Telegraf authorization not found on InfluxDB 2

    authorization not found every 10 s means InfluxDB 2 is receiving Telegraf's writes and rejecting the token: the Windows service never saw INFLUX_TOKEN set in a separate CMD session, and token = "$INFLUX_TOKEN" is not the documented substitution form. Reference the variable as "${INFLUX_TOKEN}", deliver its value in the service's startup environment, restart, and confirm the Unauthorized lines stop and the bucket fills.

    Edge computing and IIoT

  • Troubleshooting

    Telegraf MQTT consumer connects but writes no data to InfluxDB

    An empty 0 / 10000 output buffer with both the MQTT and InfluxDB connections up means no metrics are reaching Telegraf's parser. Prove live delivery with a second subscriber on a different client ID before touching parser or buffer settings: the two startup connections are independent events, and with qos = 0 and a non-persistent session, traffic published while Telegraf is offline is unrecoverable.

    Edge computing and IIoT

  • Troubleshooting

    Why Flux mqtt.publish fails with Dialer.Dial in InfluxDB

    Dialer.Dial called on an error dependency means the Flux runtime executing the task supplied no working network dialer, so mqtt.publish fails before any TCP connection to the broker. Correct the script, 1883 is the MQTT listener and 18083 the EMQX dashboard port, publish each point once with range(start: -task.every) via mqtt.to, and if the same error returns, publish with Telegraf outputs.mqtt instead of Flux.

    Edge computing and IIoT

Why an MQTT subscribe function block connects but receives nothing