github.com/influxdata/telegraf@v1.30.3/docs/TEMPLATE_PATTERN.md (about) 1 # Template Patterns 2 3 Template patterns are a mini language that describes how a dot delimited 4 string should be mapped to and from [metrics][]. 5 6 A template has the form: 7 8 ```text 9 "host.mytag.mytag.measurement.measurement.field*" 10 ``` 11 12 Where the following keywords can be set: 13 14 1. `measurement`: specifies that this section of the graphite bucket corresponds 15 to the measurement name. This can be specified multiple times. 16 2. `field`: specifies that this section of the graphite bucket corresponds 17 to the field name. This can be specified multiple times. 18 3. `measurement*`: specifies that all remaining elements of the graphite bucket 19 correspond to the measurement name. 20 4. `field*`: specifies that all remaining elements of the graphite bucket 21 correspond to the field name. 22 23 Any part of the template that is not a keyword is treated as a tag key. This 24 can also be specified multiple times. 25 26 **NOTE:** `measurement` must be specified in your template. 27 **NOTE:** `field*` cannot be used in conjunction with `measurement*`. 28 29 ## Examples 30 31 ### Measurement & Tag Templates 32 33 The most basic template is to specify a single transformation to apply to all 34 incoming metrics. So the following template: 35 36 ```toml 37 templates = [ 38 "region.region.measurement*" 39 ] 40 ``` 41 42 would result in the following Graphite -> Telegraf transformation. 43 44 ```text 45 us.west.cpu.load 100 46 => cpu.load,region=us.west value=100 47 ``` 48 49 Multiple templates can also be specified, but these should be differentiated 50 using _filters_ (see below for more details) 51 52 ```toml 53 templates = [ 54 "*.*.* region.region.measurement", # <- all 3-part measurements will match this one. 55 "*.*.*.* region.region.host.measurement", # <- all 4-part measurements will match this one. 56 ] 57 ``` 58 59 ### Field Templates 60 61 The field keyword tells Telegraf to give the metric that field name. 62 So the following template: 63 64 ```toml 65 separator = "_" 66 templates = [ 67 "measurement.measurement.field.field.region" 68 ] 69 ``` 70 71 would result in the following Graphite -> Telegraf transformation. 72 73 ```text 74 cpu.usage.idle.percent.eu-east 100 75 => cpu_usage,region=eu-east idle_percent=100 76 ``` 77 78 The field key can also be derived from all remaining elements of the graphite 79 bucket by specifying `field*`: 80 81 ```toml 82 separator = "_" 83 templates = [ 84 "measurement.measurement.region.field*" 85 ] 86 ``` 87 88 which would result in the following Graphite -> Telegraf transformation. 89 90 ```text 91 cpu.usage.eu-east.idle.percentage 100 92 => cpu_usage,region=eu-east idle_percentage=100 93 ``` 94 95 ### Filter Templates 96 97 Users can also filter the template(s) to use based on the name of the bucket, 98 using glob matching, like so: 99 100 ```toml 101 templates = [ 102 "cpu.* measurement.measurement.region", 103 "mem.* measurement.measurement.host" 104 ] 105 ``` 106 107 which would result in the following transformation: 108 109 ```text 110 cpu.load.eu-east 100 111 => cpu_load,region=eu-east value=100 112 113 mem.cached.localhost 256 114 => mem_cached,host=localhost value=256 115 ``` 116 117 ### Adding Tags 118 119 Additional tags can be added to a metric that don't exist on the received metric. 120 You can add additional tags by specifying them after the pattern. 121 Tags have the same format as the line protocol. 122 Multiple tags are separated by commas. 123 124 ```toml 125 templates = [ 126 "measurement.measurement.field.region datacenter=1a" 127 ] 128 ``` 129 130 would result in the following Graphite -> Telegraf transformation. 131 132 ```text 133 cpu.usage.idle.eu-east 100 134 => cpu_usage,region=eu-east,datacenter=1a idle=100 135 ``` 136 137 [metrics]: /docs/METRICS.md