Select Telegraf plugins with labels and selectors
Labels and selectors let you enable or disable plugin instances at startup without editing the configuration file: add labels to plugins in the configuration, then pass selectors on the command line. Inspired by Kubernetes labels, this is useful when many Telegraf instances share one configuration source, such as a configuration managed with Telegraf Controller, and each instance should run only a subset of the configured plugins.
Add labels to plugins
Add an optional labels table to any input, output, processor, or
aggregator plugin:
[[inputs.cpu]]
[inputs.cpu.labels]
app = "payments"
region = "us-east"
env = "prod"Label keys and values are plain strings that can contain alphanumeric
characters, dots (.), dashes (-), and underscores (_).
Neither keys nor values can contain wildcard characters.
labels is a TOML table, so with explicit table syntax it must come at the
end of the plugin definition.
See Table ordering.
Select plugins at startup
Pass one or more --select flags when starting Telegraf.
Each --select value is a semicolon-separated list of key-value pairs:
<key>=<value>[;<key>=<value>]- Pairs within a single
--selectvalue combine with logical AND: all must match. - Multiple
--selectflags combine with logical OR: a plugin is enabled if it matches any selector set. - Selector values support glob patterns:
*matches any number of characters and?matches a single character (for example,region=us-*). Selector keys don’t support wildcards. - Repeating the same key within a single
--selectvalue causes an error at startup. Using the same key in different--selectflags is allowed.
telegraf --config config.conf --config-directory directory/ \
--select="app=payments;region=us-*" \
--select="env=prod"Matching behavior
Telegraf matches selectors against each plugin’s labels to decide whether the plugin instance is enabled:
| Telegraf run state | Plugin has labels | Behavior |
|---|---|---|
With --select | Yes | Enabled only if a selector matches the labels |
With --select | No | Enabled (backward compatible) |
Without --select | Yes | Enabled (no selector to compare against) |
Without --select | No | Enabled (default behavior) |
A selector matches when every key-value pair in it matches a label on the plugin. Labels the selector doesn’t mention are ignored.
--select flags | Plugin labels | Result |
|---|---|---|
app=web | app="web" | Selected |
app=web | app="api" | Skipped |
app=web | app="web", region="us-east" | Selected |
app=web;region=us-west | app="web", region="us-east" | Skipped |
env=prod* | env="production" | Selected |
env=prod, env=staging | env="qa" | Skipped |
app=web;env=prod, app=api;env=prod | app="api", env="prod" | Selected |
Was this page helpful?
Thank you for your feedback!
Support and feedback
Thank you for being part of our community! We welcome and encourage your feedback and bug reports for Telegraf and this documentation. To find support, use the following resources:
Customers with an annual or support contract can contact InfluxData Support.