Skip to content

Commit 564a70d

Browse files
authored
Merge branch 'master' into jdstrand/fix-rpm-install2
2 parents 44081e7 + 6090142 commit 564a70d

File tree

11 files changed

+655
-24
lines changed

11 files changed

+655
-24
lines changed

content/telegraf/v1/configuration.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,26 @@ The following config parameters are available for all inputs:
512512
- **name_prefix**: Specifies a prefix to attach to the measurement name.
513513
- **name_suffix**: Specifies a suffix to attach to the measurement name.
514514

515+
### Data formats
516+
517+
Some output plugins support the `data_format` option, which specifies a serializer
518+
to convert metrics before writing.
519+
Common serializers include `json`, `influx`, `prometheus`, and `csv`.
520+
521+
Output plugins that support serializers may also offer `use_batch_format`, which
522+
controls whether the serializer receives metrics individually or as a batch.
523+
Batch mode enables more efficient encoding for formats like JSON arrays.
524+
525+
```toml
526+
[[outputs.file]]
527+
files = ["stdout"]
528+
data_format = "json"
529+
use_batch_format = true
530+
```
531+
532+
For available serializers and configuration options, see
533+
[output data formats](/telegraf/v1/data_formats/output/).
534+
515535
## Aggregator configuration
516536

517537
The following config parameters are available for all aggregators:
Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,41 @@
11
---
22
title: Write data with output plugins
33
description: |
4-
Output plugins define where Telegraf will deliver the collected metrics.
4+
Output plugins define where Telegraf delivers the collected metrics.
55
menu:
66
telegraf_v1:
7-
87
name: Output plugins
98
weight: 20
109
parent: Configure plugins
1110
related:
1211
- /telegraf/v1/output-plugins/
12+
- /telegraf/v1/data_formats/output/
1313
---
14-
Output plugins define where Telegraf will deliver the collected metrics. Send metrics to InfluxDB or to a variety of other datastores, services, and message queues, including Graphite, OpenTSDB, Datadog, Librato, Kafka, MQTT, and NSQ.
1514

16-
For a complete list of output plugins and links to their detailed configuration options, see [output plugins](/telegraf/v1/plugins/#output-plugins).
15+
Output plugins define where Telegraf delivers collected metrics.
16+
Send metrics to InfluxDB or to a variety of other datastores, services, and
17+
message queues, including Graphite, OpenTSDB, Datadog, Kafka, MQTT, and NSQ.
18+
19+
For a complete list of output plugins and links to their detailed configuration
20+
options, see [output plugins](/telegraf/v1/output-plugins/).
21+
22+
## Output plugins and data formats
23+
24+
Output plugins control *where* metrics go.
25+
Many output plugins also support *data formats* (serializers) that control how
26+
metrics are formatted before writing.
27+
28+
Configure a serializer using the `data_format` option in your output plugin:
29+
30+
```toml
31+
[[outputs.http]]
32+
url = "http://example.com/metrics"
33+
data_format = "json"
34+
```
35+
36+
Some output plugins (like `influxdb_v2` or `prometheus_client`) use a fixed
37+
format and don't support `data_format`.
38+
Others (like `file`, `http`, `kafka`) support multiple serializers.
1739

18-
In addition to plugin-specific data formats, Telegraf supports a set of [common data formats](/telegraf/v1/data_formats/output/) available when configuring many of the Telegraf output plugins.
40+
For available serializers and their options, see
41+
[output data formats](/telegraf/v1/data_formats/output/).

content/telegraf/v1/data_formats/output/_index.md

Lines changed: 60 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,73 @@ menu:
77
name: Output data formats
88
weight: 1
99
parent: Data formats
10+
related:
11+
- /telegraf/v1/configure_plugins/output_plugins/
12+
- /telegraf/v1/configuration/
1013
---
1114

12-
In addition to output-specific data formats, Telegraf supports the following set
13-
of common data formats that may be selected when configuring many of the Telegraf
14-
output plugins.
15+
Telegraf uses **serializers** to convert metrics into output data formats.
16+
Many [output plugins](/telegraf/v1/configure_plugins/output_plugins/) support the `data_format` option, which lets you choose
17+
how metrics are formatted before writing.
1518

16-
{{< children >}}
19+
- [How output plugins use serializers](#how-output-plugins-use-serializers)
20+
- [Choosing an output approach](#choosing-an-output-approach)
21+
- [Available serializers](#available-serializers)
22+
23+
## How output plugins use serializers
24+
25+
When you configure `data_format` in an output plugin, Telegraf uses a **serializer**
26+
to convert metrics into that format before writing.
27+
The output plugin controls *where* data goes; the serializer controls *how* it's formatted.
1728

18-
You will be able to identify the plugins with support by the presence of a
19-
`data_format` configuration option, for example, in the File (`file`) output plugin:
29+
Some output plugins support `use_batch_format`, which changes how the serializer
30+
processes metrics.
31+
When enabled, the serializer receives all metrics in a batch together rather than
32+
one at a time, enabling more efficient encoding and formats that represent multiple
33+
metrics as a unit (like JSON arrays).
2034

2135
```toml
2236
[[outputs.file]]
23-
## Files to write to, "stdout" is a specially handled file.
2437
files = ["stdout"]
2538

26-
## Data format to output.
27-
## Each data format has its own unique set of configuration options, read
28-
## more about them here:
29-
## https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_OUTPUT.md
30-
data_format = "influx"
39+
## Output plugin option: process metrics as a batch
40+
use_batch_format = true
41+
42+
## Serializer selection: format metrics as JSON
43+
data_format = "json"
3144
```
45+
46+
Output plugins that support `use_batch_format`:
47+
`file`, `http`, `amqp`, `kafka`, `nats`, `mqtt`, `exec`, `execd`, `remotefile`
48+
49+
## Choosing an output approach
50+
51+
### By destination
52+
53+
| Destination | Recommended Approach |
54+
|-------------|---------------------|
55+
| **Prometheus scraping** | [`prometheus_client`](/telegraf/v1/output-plugins/prometheus_client/) output plugin (exposes `/metrics` endpoint) |
56+
| **InfluxDB** | [`influxdb`](/telegraf/v1/output-plugins/influxdb/) or [`influxdb_v2`](/telegraf/v1/output-plugins/influxdb_v2/) output plugin (native protocol) |
57+
| **Remote HTTP endpoints** | [`http`](/telegraf/v1/output-plugins/http/) output + serializer |
58+
| **Files** | [`file`](/telegraf/v1/output-plugins/file/) output + serializer |
59+
| **Message queues** | [`kafka`](/telegraf/v1/output-plugins/kafka/), [`nats`](/telegraf/v1/output-plugins/nats/), [`amqp`](/telegraf/v1/output-plugins/amqp/) + serializer |
60+
61+
### By metric type
62+
63+
Some metric types require state across collection intervals:
64+
65+
- **Histograms** accumulate observations into buckets
66+
- **Summaries** track quantiles over a sliding window
67+
68+
Serializers process each batch independently and cannot maintain this state.
69+
When a histogram or summary spans multiple batches, the serializer may produce
70+
incomplete or incorrect output.
71+
72+
For these metric types, use a dedicated output plugin that maintains state--for example:
73+
74+
- **Prometheus metrics**: Use [`prometheus_client`](/telegraf/v1/output-plugins/prometheus_client/)
75+
instead of the prometheus serializer
76+
77+
## Available serializers
78+
79+
{{< children >}}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
---
2+
title: Binary output data format
3+
list_title: Binary
4+
description: Use the `binary` output data format (serializer) to serialize Telegraf metrics into binary protocols using user-specified configurations.
5+
menu:
6+
telegraf_v1_ref:
7+
name: Binary
8+
weight: 10
9+
parent: Output data formats
10+
identifier: output-data-format-binary
11+
---
12+
13+
Use the `binary` output data format (serializer) to serialize Telegraf metrics into binary protocols using user-specified configurations.
14+
15+
## Configuration
16+
17+
```toml
18+
[[outputs.socket_writer]]
19+
address = "tcp://127.0.0.1:54000"
20+
metric_batch_size = 1
21+
22+
## Data format to output.
23+
data_format = "binary"
24+
25+
## Specify the endianness of the data.
26+
## Available values are "little" (little-endian), "big" (big-endian) and "host",
27+
## where "host" means the same endianness as the machine running Telegraf.
28+
# endianness = "host"
29+
30+
## Definition of the message format and the serialized data.
31+
## Please note that you need to define all elements of the data in the
32+
## correct order as the binary format is position-dependent.
33+
##
34+
## Entry properties:
35+
## read_from -- Source of the data: "field", "tag", "time" or "name".
36+
## Defaults to "field" if omitted.
37+
## name -- Name of the field or tag. Can be omitted for "time" and "name".
38+
## data_format -- Target data-type: "int8/16/32/64", "uint8/16/32/64",
39+
## "float32/64", "string".
40+
## For time: "unix" (default), "unix_ms", "unix_us", "unix_ns".
41+
## string_length -- Length of the string in bytes (for "string" type only).
42+
## string_terminator -- Terminator for strings: "null", "0x00", etc.
43+
## Defaults to "null" for strings.
44+
entries = [
45+
{ read_from = "name", data_format = "string", string_length = 32 },
46+
{ read_from = "tag", name = "host", data_format = "string", string_length = 64 },
47+
{ read_from = "field", name = "value", data_format = "float64" },
48+
{ read_from = "time", data_format = "unix_ns" },
49+
]
50+
```
51+
52+
### Configuration options
53+
54+
| Option | Type | Description |
55+
|--------|------|-------------|
56+
| `endianness` | string | Byte order: `"little"`, `"big"`, or `"host"` (default) |
57+
| `entries` | array | Ordered list of data elements to serialize |
58+
59+
### Entry properties
60+
61+
Each entry in the `entries` array defines how to serialize a piece of metric data:
62+
63+
| Property | Type | Description |
64+
|----------|------|-------------|
65+
| `read_from` | string | Data source: `"field"`, `"tag"`, `"time"`, or `"name"` |
66+
| `name` | string | Field or tag name (required for `"field"` and `"tag"`) |
67+
| `data_format` | string | Target type: `"int8/16/32/64"`, `"uint8/16/32/64"`, `"float32/64"`, `"string"` |
68+
| `string_length` | integer | Fixed string length in bytes (for `"string"` type) |
69+
| `string_terminator` | string | String terminator: `"null"`, `"0x00"`, etc. |
70+
71+
## Type conversion
72+
73+
If the original field type differs from the target type, the serializer converts the value.
74+
A warning is logged if the conversion may cause loss of precision.
75+
76+
## String handling
77+
78+
For string fields:
79+
- If the string is longer than `string_length`, it is truncated so that the string and its terminator together fit within `string_length` bytes
80+
- If the string is shorter than `string_length`, it is padded with the terminator character so that the string and its terminator together occupy `string_length` bytes
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
---
2+
title: CloudEvents output data format
3+
list_title: CloudEvents
4+
description: Use the `cloudevents` output data format (serializer) to format Telegraf metrics as CloudEvents in JSON format.
5+
menu:
6+
telegraf_v1_ref:
7+
name: CloudEvents
8+
weight: 10
9+
parent: Output data formats
10+
identifier: output-data-format-cloudevents
11+
---
12+
13+
Use the `cloudevents` output data format (serializer) to format Telegraf metrics as [CloudEvents](https://cloudevents.io) in [JSON format](https://github.com/cloudevents/spec/blob/v1.0/json-format.md).
14+
Versions v1.0 and v0.3 of the CloudEvents specification are supported, with v1.0 as the default.
15+
16+
## Configuration
17+
18+
```toml
19+
[[outputs.file]]
20+
files = ["stdout", "/tmp/metrics.out"]
21+
22+
## Data format to output.
23+
data_format = "cloudevents"
24+
25+
## Specification version to use for events.
26+
## Supported versions: "0.3" and "1.0" (default).
27+
# cloudevents_version = "1.0"
28+
29+
## Event source specifier.
30+
## Overwrites the source header field with the given value.
31+
# cloudevents_source = "telegraf"
32+
33+
## Tag to use as event source specifier.
34+
## Overwrites the source header field with the value of the specified tag.
35+
## Takes precedence over 'cloudevents_source' if both are set.
36+
## Falls back to 'cloudevents_source' if the tag doesn't exist for a metric.
37+
# cloudevents_source_tag = ""
38+
39+
## Event-type specifier to overwrite the default value.
40+
## Default for single metric: 'com.influxdata.telegraf.metric'
41+
## Default for batch: 'com.influxdata.telegraf.metrics' (plural)
42+
# cloudevents_event_type = ""
43+
44+
## Set time header of the event.
45+
## Supported values:
46+
## none -- do not set event time
47+
## earliest -- use timestamp of the earliest metric
48+
## latest -- use timestamp of the latest metric
49+
# cloudevents_time = "earliest"
50+
```
51+
52+
### Configuration options
53+
54+
| Option | Type | Default | Description |
55+
|--------|------|---------|-------------|
56+
| `cloudevents_version` | string | `"1.0"` | CloudEvents specification version (`"0.3"` or `"1.0"`) |
57+
| `cloudevents_source` | string | `"telegraf"` | Event source identifier |
58+
| `cloudevents_source_tag` | string | `""` | Tag to use as source (overrides `cloudevents_source`) |
59+
| `cloudevents_event_type` | string | auto | Event type (auto-detected based on single/batch) |
60+
| `cloudevents_time` | string | `"earliest"` | Event timestamp: `"none"`, `"earliest"`, or `"latest"` |
61+
62+
## Event types
63+
64+
By default, the serializer sets the event type based on the content:
65+
- Single metric: `com.influxdata.telegraf.metric`
66+
- Batch of metrics: `com.influxdata.telegraf.metrics`
67+
68+
Use `cloudevents_event_type` to override this behavior.

0 commit comments

Comments
 (0)