Moved template patterns info under the only two data formats it applies (addresses #3899 ) (#4075)

Co-authored-by: lwandzura <51929958+lwandzura@users.noreply.github.com>
pull/4071/head^2
noramullen1 2022-06-01 13:07:07 -07:00 committed by GitHub
parent a39874f8db
commit 5824d5ff74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 284 additions and 149 deletions

View File

@ -7,12 +7,12 @@ menu:
name: Dropwizard
weight: 30
parent: Input data formats
aliases:
- /telegraf/v1.22/data_formats/template-patterns/
---
The `dropwizard` data format can parse a [Dropwizard JSON representation][dropwizard] representation of a single metrics registry. By default, tags are parsed from metric names as if they were actual InfluxDB Line Protocol keys (`measurement<,tag_set>`) which can be overridden using custom [template patterns][templates]. All field value types are supported, including `string`, `number` and `boolean`.
The `dropwizard` data format can parse a [Dropwizard JSON representation](http://metrics.dropwizard.io/3.1.0/manual/json/) representation of a single metrics registry. By default, tags are parsed from metric names as if they were actual InfluxDB Line Protocol keys (`measurement<,tag_set>`) which can be overridden using custom [template patterns](#templates). All field value types are supported, including `string`, `number` and `boolean`.
[templates]: /telegraf/v1.15/data_formats/template-patterns/
[dropwizard]: http://metrics.dropwizard.io/3.1.0/manual/json/
## Configuration
@ -178,3 +178,143 @@ dropwizard_tags_path = "tags"
# tag1 = "tags.tag1"
# tag2 = "tags.tag2"
```
## Templates <!--This content is duplicated in /telegraf/v1.22/data_formats/input/graphite/-->
Template patterns are a mini language that describes how a dot-delimited
string should be mapped to and from [metrics](/telegraf/v1.22/concepts/metrics/).
A template has the following format:
```
"host.mytag.mytag.measurement.measurement.field*"
```
You can set the following keywords:
- `measurement`: Specifies that this section of the graphite bucket corresponds
to the measurement name. This can be specified multiple times.
- `field`: Specifies that this section of the graphite bucket corresponds
to the field name. This can be specified multiple times.
- `measurement*`: Specifies that all remaining elements of the graphite bucket
correspond to the measurement name.
- `field*`: Specifies that all remaining elements of the graphite bucket
correspond to the field name.
{{% note %}}
`field*` can't be used in conjunction with `measurement*`.
{{% /note %}}
Any part of the template that isn't a keyword is treated as a tag key, which can also be used multiple times.
### Examples
#### Measurement and tag templates
The most basic template is to specify a single transformation to apply to all
incoming metrics.
##### Template
```toml
templates = [
"region.region.measurement*"
]
```
##### Resulting transformation
```
us.west.cpu.load 100
=> cpu.load,region=us.west value=100
```
You can also specify multiple templates using [filters](#filter-templates).
```toml
templates = [
"*.*.* region.region.measurement", # <- all 3-part measurements will match this one.
"*.*.*.* region.region.host.measurement", # <- all 4-part measurements will match this one.
]
```
#### Field templates
The field keyword tells Telegraf to give the metric that field name.
##### Template
```toml
separator = "_"
templates = [
"measurement.measurement.field.field.region"
]
```
##### Resulting transformation
```
cpu.usage.idle.percent.eu-east 100
=> cpu_usage,region=eu-east idle_percent=100
```
You can also derive the field key from all remaining elements of the graphite
bucket by specifying `field*`.
##### Template
```toml
separator = "_"
templates = [
"measurement.measurement.region.field*"
]
```
##### Resulting transformation
```
cpu.usage.eu-east.idle.percentage 100
=> cpu_usage,region=eu-east idle_percentage=100
```
#### Filter templates
You can also filter templates based on the name of the bucket
using a wildcard.
##### Template
```toml
templates = [
"cpu.* measurement.measurement.region",
"mem.* measurement.measurement.host"
]
```
##### Resulting transformation
```
cpu.load.eu-east 100
=> cpu_load,region=eu-east value=100
mem.cached.localhost 256
=> mem_cached,host=localhost value=256
```
#### Adding tags
You can add additional tags to a metric that don't exist on the received metric by specifying them after the pattern. Tags have the same format as the line protocol.
Separate multiple tags with commas.
##### Template
```toml
templates = [
"measurement.measurement.field.region datacenter=1a"
]
```
##### Resulting transformation
```
cpu.usage.idle.eu-east 100
=> cpu_usage,region=eu-east,datacenter=1a idle=100

View File

@ -7,6 +7,8 @@ menu:
name: Graphite
weight: 40
parent: Input data formats
aliases:
- /telegraf/v1.22/data_formats/template-patterns/
---
The Graphite data format translates Graphite *dot* buckets directly into
@ -51,6 +53,143 @@ By default, the separator is left as `.`, but this can be changed using the
]
```
### templates
## Templates
For information on creating templates, see [Template patterns](/telegraf/v1.15/data_formats/template-patterns/).
Template patterns are a mini language that describes how a dot-delimited
string should be mapped to and from [metrics](/telegraf/v1.22/concepts/metrics/).
A template has the following format:
```
"host.mytag.mytag.measurement.measurement.field*"
```
You can set the following keywords:
- `measurement`: Specifies that this section of the graphite bucket corresponds
to the measurement name. This can be specified multiple times.
- `field`: Specifies that this section of the graphite bucket corresponds
to the field name. This can be specified multiple times.
- `measurement*`: Specifies that all remaining elements of the graphite bucket
correspond to the measurement name.
- `field*`: Specifies that all remaining elements of the graphite bucket
correspond to the field name.
{{% note %}}
`field*` can't be used in conjunction with `measurement*`.
{{% /note %}}
Any part of the template that isn't a keyword is treated as a tag key, which can also be used multiple times.
### Examples
#### Measurement and tag templates
The most basic template is to specify a single transformation to apply to all
incoming metrics.
##### Template <!--This content is duplicated in /telegraf/v1.22/data_formats/input/graphite/-->
```toml
templates = [
"region.region.measurement*"
]
```
##### Resulting transformation
```
us.west.cpu.load 100
=> cpu.load,region=us.west value=100
```
You can also specify multiple templates using [filters](#filter-templates).
```toml
templates = [
"*.*.* region.region.measurement", # <- all 3-part measurements will match this one.
"*.*.*.* region.region.host.measurement", # <- all 4-part measurements will match this one.
]
```
#### Field templates
The field keyword tells Telegraf to give the metric that field name.
##### Template
```toml
separator = "_"
templates = [
"measurement.measurement.field.field.region"
]
```
##### Resulting transformation
```
cpu.usage.idle.percent.eu-east 100
=> cpu_usage,region=eu-east idle_percent=100
```
You can also derive the field key from all remaining elements of the graphite
bucket by specifying `field*`.
##### Template
```toml
separator = "_"
templates = [
"measurement.measurement.region.field*"
]
```
##### Resulting transformation
```
cpu.usage.eu-east.idle.percentage 100
=> cpu_usage,region=eu-east idle_percentage=100
```
#### Filter templates
You can also filter templates based on the name of the bucket
using a wildcard.
##### Template
```toml
templates = [
"cpu.* measurement.measurement.region",
"mem.* measurement.measurement.host"
]
```
##### Resulting transformation
```
cpu.load.eu-east 100
=> cpu_load,region=eu-east value=100
mem.cached.localhost 256
=> mem_cached,host=localhost value=256
```
#### Adding tags
You can add additional tags to a metric that don't exist on the received metric by specifying them after the pattern. Tags have the same format as the line protocol.
Separate multiple tags with commas.
##### Template
```toml
templates = [
"measurement.measurement.field.region datacenter=1a"
]
```
##### Resulting transformation
```
cpu.usage.idle.eu-east 100
=> cpu_usage,region=eu-east,datacenter=1a idle=100
```

View File

@ -1,144 +0,0 @@
---
title: Telegraf template patterns
description: Use template patterns to describe how dot-delimited strings should map to and from Telegraf metrics.
menu:
telegraf_1_22_ref:
name: Template patterns
weight: 30
parent: Data formats
---
Template patterns are a mini language that describes how a dot delimited
string should be mapped to and from [metrics][].
A template has the form:
```
"host.mytag.mytag.measurement.measurement.field*"
```
Where the following keywords can be set:
1. `measurement`: specifies that this section of the graphite bucket corresponds
to the measurement name. This can be specified multiple times.
2. `field`: specifies that this section of the graphite bucket corresponds
to the field name. This can be specified multiple times.
3. `measurement*`: specifies that all remaining elements of the graphite bucket
correspond to the measurement name.
4. `field*`: specifies that all remaining elements of the graphite bucket
correspond to the field name.
Any part of the template that is not a keyword is treated as a tag key. This
can also be specified multiple times.
**NOTE:** `field*` cannot be used in conjunction with `measurement*`.
## Examples
### Measurement and tag templates
The most basic template is to specify a single transformation to apply to all
incoming metrics. So the following template:
```toml
templates = [
"region.region.measurement*"
]
```
would result in the following Graphite -> Telegraf transformation.
```
us.west.cpu.load 100
=> cpu.load,region=us.west value=100
```
Multiple templates can also be specified, but these should be differentiated
using _filters_ (see below for more details)
```toml
templates = [
"*.*.* region.region.measurement", # <- all 3-part measurements will match this one.
"*.*.*.* region.region.host.measurement", # <- all 4-part measurements will match this one.
]
```
### Field templates
The field keyword tells Telegraf to give the metric that field name.
So the following template:
```toml
separator = "_"
templates = [
"measurement.measurement.field.field.region"
]
```
would result in the following Graphite -> Telegraf transformation.
```
cpu.usage.idle.percent.eu-east 100
=> cpu_usage,region=eu-east idle_percent=100
```
The field key can also be derived from all remaining elements of the graphite
bucket by specifying `field*`:
```toml
separator = "_"
templates = [
"measurement.measurement.region.field*"
]
```
which would result in the following Graphite -> Telegraf transformation.
```
cpu.usage.eu-east.idle.percentage 100
=> cpu_usage,region=eu-east idle_percentage=100
```
### Filter templates
Users can also filter the template(s) to use based on the name of the bucket,
using glob matching, like so:
```toml
templates = [
"cpu.* measurement.measurement.region",
"mem.* measurement.measurement.host"
]
```
which would result in the following transformation:
```
cpu.load.eu-east 100
=> cpu_load,region=eu-east value=100
mem.cached.localhost 256
=> mem_cached,host=localhost value=256
```
### Adding Tags
Additional tags can be added to a metric that don't exist on the received metric.
You can add additional tags by specifying them after the pattern.
Tags have the same format as the line protocol.
Multiple tags are separated by commas.
```toml
templates = [
"measurement.measurement.field.region datacenter=1a"
]
```
would result in the following Graphite -> Telegraf transformation.
```
cpu.usage.idle.eu-east 100
=> cpu_usage,region=eu-east,datacenter=1a idle=100
```
[metrics]: /telegraf/v1.15/concepts/metrics/