Explainer
Why Telegraf 401 comes from the v1 output on InfluxDB 2
Short answer
Telegraf 1.16.2 sends 401 Unauthorized because its v1 output authenticates with a username and password, and InfluxDB OSS 2.x accepts only tokens. The influx CLI profile in .influxdbv2/configs fills flags for influx commands and is invisible to Telegraf. Replace the block with the v2 output and pass urls, token, organization and bucket, for example through environment variables.

On this page
- Why does Telegraf return 401 Unauthorized with the right password?
- Which output plugin does InfluxDB 2.x actually need?
- Why can't Telegraf use the influx CLI profile?
- How do you pass the token without breaking upgrades?
- What does the corrected configuration look like?
- How do you prove the fix worked?
- What if 401 Unauthorized still appears after the switch?
- Questions asked
Telegraf 1.16.2 with an [[outputs.influxdb]] block writes nothing to InfluxDB OSS 2.x when it authenticates with a username and password: the server answers 401 Unauthorized on the database creation and again on every flush, and the agent gives up with could not write any address. The password is not wrong; the authentication scheme is. InfluxDB 2.x issues tokens instead of v1 credentials, and the influx CLI profile that works on the command line is invisible to Telegraf. The fix is the [[outputs.influxdb_v2]] output, configured with urls, token, organization and bucket.
Why does Telegraf return 401 Unauthorized with the right password? #
The 401 comes from an authentication mismatch: the outputs.influxdb block in Telegraf 1.16.2 sends a username and password, while InfluxDB OSS 2.x authenticates with tokens, so the server rejects both the database creation and every write.
A failing start has a fixed signature. The log reports Loaded outputs: influxdb, so the v1 plugin parsed; ten seconds later come database "telegraf" creation failed: 401 Unauthorized and then [agent] Error writing to outputs.influxdb: could not write any address. The block carries the full v1 credential set, urls = ["http://127.0.0.1:8086"], database = "telegraf", retention_policy = "influx_retention", username and password, and that set is exactly what a 2.x server refuses.
InfluxDB OSS 2.x expects a token in the Authorization header of each API request. The v1 output sends a Basic-auth username and password pair and no token; a 2.x server with no v1-style user mapping configured has nothing to check that pair against, so every request bounces. The credentials can be perfectly correct for a 1.x server and still be refused here, so retyping the password or resetting the user changes nothing.
The decision at this point: this is a generation mismatch between the output plugin and the database, not a mistyped secret. Stop debugging the password and replace the output block.
Which output plugin does InfluxDB 2.x actually need? #
InfluxDB 2.x needs [[outputs.influxdb_v2]], the plugin that writes metrics to a v2.x instance over HTTP, and its settings are urls, token, organization and bucket; the v1 block's database, retention_policy, username and password have no place in it.
The mapping is nearly one for one. urls keeps the same base address, the host and port 8086 already in the file. token replaces the username and password pair. organization is new, because 1.x had no organizations. bucket replaces database together with retention_policy: in 2.x a bucket carries its own retention period, so the separate policy setting disappears.
Delete the entire v1 block rather than parking it beside the new one. A leftover [[outputs.influxdb]] repeats its failing request on every flush interval even while the v2 block writes correctly, so the log stays red and the next engineer cannot tell which plugin produced the error.
Why can't Telegraf use the influx CLI profile? #
A profile in .influxdbv2/configs exists only for influx commands: influx config list shows a name, URL, organization and token, and those values fill the flags of influx commands only; Telegraf never reads that file.
That file, in the home directory of the user who runs the influx CLI, is a convenience store for one program. It lets influx commands run without typing the host, organization and token flags every time, and its scope ends there. Telegraf reads its telegraf.conf, the environment of its own process, and nothing belonging to the influx CLI, so a profile marked active proves nothing about what Telegraf will send.
One more trap sits in how such a profile is made: influx config create stores whatever string is passed to its -t option as the token, without asking the server anything. A profile can look complete, with URL, organization, token and active set, while its token field holds a string the server never issued, such as the same password that fails inside Telegraf. Only a token created through InfluxDB's own token management authenticates a write.
How do you pass the token without breaking upgrades? #
Export INFLUX_HOST, INFLUX_TOKEN and INFLUX_ORG in the environment of whatever launches the Telegraf process, a service unit, a container definition or the shell that starts it by hand, because a token exported in one terminal never reaches a service started elsewhere.
The environment must be the one the process actually inherits: a systemd unit reads its own environment settings, a container reads its definition, and neither reads an interactive shell's exports. Confirm delivery by starting Telegraf once from the shell where the variables are set; if the rejection vanishes there and persists under the service, the service environment was the gap.
The value also has to survive package maintenance. An export dies with its terminal, and a hand-edited unit file can be overwritten when the telegraf package is upgraded, so the same 401 reappears after a routine update; configuring the Telegraf INFLUX_TOKEN to survive apt upgrades works through where the variable belongs so an upgrade cannot remove it.
One security note: with the token in the environment, telegraf.conf can go into version control with no secret inside it, so commit the config and never the token.
What does the corrected configuration look like? #
Replace the v1 block with the v2 block below, built on the example values already in play: host http://localhost:8086, organization demo.net, bucket telegraf, and a token named in words because only the server-issued string works.
Set the environment first:
export INFLUX_HOST=http://localhost:8086
export INFLUX_ORG=demo.net
export INFLUX_TOKEN=the-write-token-issued-by-the-server
Then the output block in telegraf.conf:
[[outputs.influxdb_v2]]
urls = ["$INFLUX_HOST"]
token = "$INFLUX_TOKEN"
organization = "$INFLUX_ORG"
bucket = "telegraf"
Telegraf resolves the dollar-prefixed names from its process environment as it parses the file, so the configuration itself carries no secret. The bucket must already exist before the first write, because the v2 output does not create it. Create telegraf in organization demo.net with the retention period the old influx_retention policy implied; that is where the retention setting now lives.
How do you prove the fix worked? #
Start Telegraf with the intended file, /usr/bin/telegraf --config /etc/telegraf/telegraf.conf, and read the first log screen: Loaded outputs: influxdb_v2 must replace Loaded outputs: influxdb, and the database-creation warning must disappear because the v2 output has no creation step.
Then check the data, not just the log. With the example settings, agent interval 10 s and flush interval 10 s, each field gains one point every 10 s, so a query over the last 60 s should return about 6 points per field: 60 s divided by 10 s gives 6. A clean log with zero points puts the fault on the query side, in the wrong bucket, the wrong organization or a token without read access, not on the write.
If the log shows E! lines naming every configured server instead, that is a different fault with its own signature, covered in why Telegraf failed to send metrics to any configured server.
Do not verify with a bare status code. On InfluxDB OSS 2.0 a request to a wrong path can still return 200, as why InfluxDB OSS 2.0 returns HTTP 200 for bad URLs explains, so a green HTTP check proves nothing about the write path; read the points back from the bucket instead.
What if 401 Unauthorized still appears after the switch? #
When the v2 output is loaded and the server still answers 401, the cause is one of three, checked in this order: the token belongs to another organization, the token lacks write permission on the bucket, or the process never received the token and sent an empty value.
Check the organization string first, since it must match exactly, demo.net in the example. Then check the token's scope with a diagnostic: an all-access token used once, only to isolate permissions. If it writes where the scoped token cannot, the scope is the fault, not the network or the URL; issue a token with write on that one bucket and put it back in place of the all-access one. Finally check delivery: an empty INFLUX_TOKEN in the service environment produces the same rejection as a wrong one.
One case sits outside this list. A plant that keeps the v1 output on purpose, writing through the 2.x server's v1 compatibility endpoints, gets its 401 on database creation from the listener and compatibility service rather than from the plugin choice, and check the listener when 401 comes on database creation walks that path.
The decisions, case by case: a v1 block against a 2.x server gets replaced with [[outputs.influxdb_v2]]; credentials that live only in an influx CLI profile get moved into Telegraf's own environment or configuration; a 401 that survives the switch gets its token's organization, scope and delivery fixed, in that order.
Questions asked
Why does the v1 output try to create a database before writing?
The database option makes the v1 output send a create-database request before its first write, which is why the rejection shows twice: once at creation, once at the first flush. The v2 output has no creation step; it writes into a bucket that must already exist in the organization before Telegraf starts.
Can the v1 and v2 output blocks run side by side?
Mechanically yes. Both blocks load, the v2 block writes, and the v1 block repeats its failing request every flush interval, every 10 s under the example settings, so the log fills with errors. If the v1 path ever succeeded, the same metrics would land twice, once per destination. Remove the v1 block as soon as the v2 write is verified.
How do I issue a token that can write to the bucket?
In InfluxDB's own token management, the API tokens page of the web UI or the influx CLI's authorization commands, create an access token scoped to the organization with write permission on that one bucket. The string must come from the server; a token typed by hand into a CLI profile was never issued and authenticates nothing.
Can several Telegraf hosts share one write token?
Yes. A token scoped to write on that one bucket works from any number of hosts, and each Telegraf instance stamps its points with its own host tag, so the streams stay separable in the bucket. The trade is blast radius: revoking that token stops every host at once, which is also what makes a leaked token quick to kill.


