Skip to main content
Version: Next

Telegraf

The Telegraf module (io.scadex.driver.telegraf) lets Telegraf agents, and anything else that writes InfluxDB line protocol, push their measurements to the gateway. Each series you choose becomes a tag, so a host's CPU load or an SNMP counter can have an alarm, a screen and history like any other tag. This page is for engineers who already run Telegraf, or want to: it covers adding an agent, the address and key it sends with, the configuration to paste, and what the gateway does with what arrives.

Nothing is installed on the agent. Telegraf's own outputs.influxdb_v2 or outputs.http points at the gateway, and its inputs (host metrics, SNMP, Docker, MQTT and the rest) become tags. The module has no third-party dependency: it reads the line protocol and Telegraf's JSON itself. It is version 1.0.0 and declares SDK contract 1.6.

The other direction needs no module: Telegraf can read the gateway's values from the MQTT broker or from an event stream, and pass them on to its own outputs.

What has been tried​

The module has run against one real Telegraf, version 1.34, on the development machine and nowhere else. inputs.mem and inputs.exec went out through outputs.influxdb_v2 with a Token key, and through outputs.http as gzip line protocol and as JSON with a Bearer key. The tags took live values of every type, a replay of old points was dropped, and a stopped agent turned its tags bad after the stale limit and good again when it came back.

Other Telegraf versions, other inputs, other writers of line protocol (Grafana Agent, Node-RED, a script), an agent behind a proxy or over https, and many agents at once have not been tried. No plant has used it yet.

Adding an agent​

A connection is one agent, or a group of agents that should share tags. Nothing is dialled: the agent connects to the gateway.

  1. Open Connections, then Devices, then Telegraf (/connections/io.scadex.driver.telegraf), and choose Add agent. On the Connections overview the same button reads Add Telegraf agent. A panel opens beside the list.
  2. Give it a Name (up to 80 characters, unique among the module's connections, no control characters). Leave Enabled on.
  3. Under Settings, set Stale after (seconds): how long the connection may go without any data before its tags read bad. The default is 60; 0 never; the most is 86400. See A silent agent.
  4. Choose Add agent.

On the connection's page, Test says whether an agent is sending:

WhenWhat it says
An agent is sending"Data arrived 3 s ago. 42 series seen."
Nothing has arrived since the connection started"Nothing has arrived from an agent yet. Set up the agent to send to this connection, then test again."
Data stopped for the stale limit"No data from the agent for 60 s"
Enabled is off"The connection is switched off, so it takes nothing."

The page has the tabs Tags, New tag, Browse, Set up the agent and Diagnostics. Engineers and administrators see all five; other roles see Tags and Diagnostics. Set up the agent shows a telegraf.conf for this connection, with the address this browser used already in it, in a block with a copy button.

The address​

An agent posts to one of two addresses, where {connectionId} is the connection's id:

  • POST /api/v1/modules/io.scadex.driver.telegraf/ingest/{connectionId}/api/v2/write is InfluxDB's write route. It is what outputs.influxdb_v2 builds from urls = [".../ingest/{connectionId}"].
  • POST /api/v1/modules/io.scadex.driver.telegraf/ingest/{connectionId} is for outputs.http, and for anything else that posts to a URL as it is.

The body is InfluxDB line protocol, or Telegraf JSON when its first character that isn't a space is { or [: one metric, several one after another, a list, or {"metrics":[...]} from use_batch_format. It may be plain or compressed with gzip (or deflate) and is read as UTF-8. The query parameter precision (ns, us, ms or s; default ns) is the unit of the timestamps in line protocol; JSON timestamps are always seconds.

The gateway answers when the points are queued, not when they are published:

AnswerWhen
204The body was read. An empty body, or one with only comments, is also 204
400Something in it could not be read. The lines that could be read were still taken. A precision that is not one of the four, or a body that is not valid for its Content-Encoding, is also 400
401, 403No valid API key, or a key without the operator role
404The connection does not exist or is switched off
413More than 8 MiB, as sent or once decompressed
415A Content-Encoding other than gzip or deflate
503The module is stopped

A 400 body names the first fault and counts the rest:

{ "code": "invalid", "message": "line 3: field 'x' has no value.", "line": 3, "rejected": 2, "accepted": 10 }

Who may send​

An agent signs in with an API key that has the Operator role. Make one under Gateway, then Security, then API keys; API keys has the steps. Send it as either of:

Authorization: Token scx_...
Authorization: Bearer scx_...

Token is how InfluxDB clients send their token, which is what Telegraf's token setting does, so a stock outputs.influxdb_v2 works as it is. The gateway reads the Token scheme for keys that start with scx_ only. No session and no Origin header are needed.

Give an agent an operator key, so it can write values and do nothing else: it cannot make or change connections or tags. A viewer's key is refused with 403. Revoking the key stops the agent at once. One key can serve every agent, or each agent can have its own so that one can be revoked alone: the gateway does not limit a key to one connection.

The Telegraf configuration​

This is what Set up the agent shows, with <the gateway's address> where the dashboard puts the address in its own address bar. Replace <the connection's id> with the connection's id and <an API key with the operator role> with the key.

[[outputs.influxdb_v2]]
urls = ["<the gateway's address>/api/v1/modules/io.scadex.driver.telegraf/ingest/<the connection's id>"]
token = "<an API key with the operator role>"
organization = "scadex"
bucket = "scadex"

The gateway reads nothing from organization and bucket, but Telegraf's output needs both set, so any text will do. Telegraf compresses the body with gzip by default, which the gateway accepts.

The same with the generic HTTP output, as line protocol:

[[outputs.http]]
url = "<the gateway's address>/api/v1/modules/io.scadex.driver.telegraf/ingest/<the connection's id>"
method = "POST"
data_format = "influx"
content_encoding = "gzip"
[outputs.http.headers]
Authorization = "Bearer <an API key with the operator role>"

Or as JSON:

[[outputs.http]]
url = "<the gateway's address>/api/v1/modules/io.scadex.driver.telegraf/ingest/<the connection's id>"
method = "POST"
data_format = "json"
use_batch_format = true
json_timestamp_units = "1s"
[outputs.http.headers]
Authorization = "Bearer <an API key with the operator role>"

A JSON timestamp is read as seconds, which is what Telegraf writes unless json_timestamp_units says otherwise. A number in milliseconds or finer is far past the year 9999, so the gateway refuses it with a sentence that says to set json_timestamp_units = "1s" or to send line protocol, instead of taking it for a date.

Restart Telegraf after changing its configuration. What it sends appears under Browse on the connection.

Series and tags​

A series is one field of one measurement with one set of tags. For this line:

cpu,cpu=cpu0,host=pc01 usage_idle=97.2,usage_system=1.9 1700000000000000000

there are two series: usage_idle and usage_system of the measurement cpu with the tags cpu=cpu0,host=pc01.

The gateway keeps a catalog of the series it has seen: at most 5,000, and when it is full the one seen least recently is forgotten. The catalog is in memory, so it is empty after a restart until the agent sends again. Only series that a tag follows are published as values; the rest are only counted in the catalog.

The gateway offers a module no way to make tags, so they are made the way every driver's are, by browsing:

  1. Open the connection's Browse tab. The first level lists measurements, then Open one to see its tag sets, then Open a tag set to see its fields with the last value sent. Read this folder again (the refresh button) reads the catalog again.
  2. Tick the fields you want. Select all at the top of a folder ticks every field in it, so one host's forty memory fields are one click.
  3. Under the list, enter the path to create the tags under in the box Tag path to create them under, then choose Create 3 tags (the count follows what is ticked). Until something is ticked, the button reads Tick values to create tags.

A tag is named after its series: <the path you entered>.<measurement>.<tag values joined by _>.<field>. The tag values come in the order of their keys. In the example above, with Telegraf entered, the tags are:

Telegraf.cpu.cpu0_pc01.usage_idle
Telegraf.cpu.cpu0_pc01.usage_system

A dot is the separator of a path, so inside a name anything but a letter, a digit, _ and - is replaced by _ (a host named pc01.plant becomes pc01_plant). Two series that would get the same path in one request are told apart by _2, _3 and so on. A tag that is new, or restarted, takes the last value the agent sent for its series at once, so tags made from Browse have values without waiting for the next point.

The binding​

A tag follows a series by its binding, which the New tag tab also takes by hand:

{ "measurement": "cpu", "tags": "cpu=cpu0,host=pc01", "field": "usage_idle" }
FieldMeaning
MeasurementThe measurement the agent sends. Required
TagsEvery tag of the series as name=value pairs separated by commas, in any order. Empty for a series with no tags
FieldThe name of one value of the measurement. Required

The match is exact: a series with a tag the binding leaves out is another series. A binding that cannot be read makes its tag bad with the reason; it is never marked stale over it. Through the API, an id of a measurement or of a tag set given to the discover route stands for all its fields.

Data types​

What the agent sends decides the tag's data type when Browse makes it:

Sent asExampleTag data type
A float97.2Double
An integer, with i5iInt64
An unsigned integer, with u5uUInt64
true or falset, true, FalseBoolean
A string, in quotes"on"String

A Double tag also takes integers, which widen. A tag of another type takes only what fits: an Int32 tag takes whole numbers inside its range. When a field no longer fits its tag, for example an integer field the agent now sends as a float, the tag reads bad with the reason (The agent sent a float, which doesn't fit this tag's data type (Int64).) and keeps its last value and its type.

Telegraf's JSON has less to say than line protocol:

  • JSON has one kind of number, so every number in it is a float, and a tag made from it is Double. It cannot tell 5 from 5.0. Send line protocol where integers matter.
  • Whole numbers above 2^53 lose their last digits, because they are read as a double.
  • The timestamp is in whole seconds unless json_timestamp_units says finer, which the gateway refuses.

Time and order​

The point's own timestamp is the value's source timestamp. A point without one is stamped when it arrives. A point more than a minute in the future is stamped with the time it arrived, and counted as futureClamped in the module's status.

A point older than the last one published for that tag is dropped and counted (outOfOrder). The tag runtime keeps whatever arrives last, so an agent replaying its buffer after an outage can never put an old value over a newer one. A point with the same time as the last is taken. Within one request, the points of one tag are published in order.

A silent agent​

An agent pushes when it likes and has no heartbeat, so a silent one cannot be told from a quiet one. Stale after (seconds) is how long a connection may go without any data. After that its tags read bad (No data from the agent for 60 s), keeping their last values, and the connection reads as disconnected. Data brings them back. The limit counts from the connection's start when nothing has arrived at all, so an agent that never comes is noticed too. A limit of 0 never goes stale.

The limit is per connection, not per series or per agent: one agent that keeps sending keeps every tag of its connection good, even tags whose own series stopped. Put agents that should be judged separately on separate connections.

A connection is in one of these states, shown by GET /api/v1/modules/io.scadex.driver.telegraf/status as state:

StateMeaning
waitingNothing has arrived yet, and the stale limit has not passed since the connection started
receivingData arrived, and the stale limit has not passed since the last of it
staleNothing has arrived for the stale limit
stoppedThe connection has been shut down

When the module stops, the gateway marks the tags it owns bad, keeping their last values, as it does for every module.

Limits​

  • A request holds at most 8 MiB, as sent and once decompressed. A larger one is refused with 413.
  • A name (measurement, tag key, field) or a tag value is at most 512 characters.
  • Samples wait in a queue of 16,384 per connection and are published in batches of 256. When the queue is full the oldest are dropped and counted (dropped), so a gateway that falls behind never holds the agent up or grows its memory.
  • The request is answered when the points are queued, not when they are stored.
  • A bad line costs only itself, and only the first 20 faults of a request are kept for the answer; the rest are counted.
  • The catalog holds 5,000 series, in memory.

Health tags and status​

Each connection is published every two seconds under [system]connection.telegraf.<name>.*, where <name> is the connection name turned into a path segment. The leaves are name, state (disabled, connecting, connected or faulted: connecting while the agent is waiting, connected while receiving, faulted once stale), connected, enabled, address, tags, error and since, plus these from the module:

LeafMeaning
valuesPerSecond, messagesPerSecondValues published and points received per second
good, uncertain, bad, waitingHow many of the bound tags have each last quality
seriesHow many series the catalog holds
pointsLines and metrics read
rejectedLinesLines and metrics that could not be read
droppedSamples thrown away because the queue was full
outOfOrderPoints dropped for being older than the last one published
lastReceivedWhen data last arrived, ISO 8601

Numbers and booleans are real tags with history; text is live only. See Databases and storage for how the connection tags work.

Besides the standard driver routes, the module has these, where ... stands for /api/v1/modules/io.scadex.driver.telegraf:

  • GET /api/v1/modules/io.scadex.driver.telegraf/status (viewer): each running connection with its state, stateChangedAt, tagCount, seriesCount, pointsReceived, rejectedLines, droppedSamples, outOfOrder, futureClamped and lastReceived.
  • GET .../connections/{id}/series?measurement=&limit= (viewer): the catalog. Each series has measurement, tags, field, type, the last value, measured, lastSeen and points, and the answer has capacity, count and evicted. limit defaults to 1000.
  • GET .../connections/{id}/setup (viewer): the telegraf.conf as {title, language, text}, with {origin} where the gateway's address goes.
  • POST .../ingest/{connectionId} and POST .../ingest/{connectionId}/api/v2/write (operator): what an agent posts to, as above.

Any signed-in user may read the catalog, because it is data a viewer can read from the tags anyway.

For a worked example from the agent to InfluxDB, see Telegraf to InfluxDB.