docs(inputs.mqtt_consumer): add pivot example to readme (#11195)
This commit is contained in:
parent
2f6701013b
commit
5598a16bdb
|
|
@ -87,6 +87,13 @@ and creates metrics using one of the supported [input data formats][].
|
||||||
# key = type
|
# key = type
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Example Output
|
||||||
|
|
||||||
|
```text
|
||||||
|
mqtt_consumer,host=pop-os,topic=telegraf/host01/cpu value=45i 1653579140440951943
|
||||||
|
mqtt_consumer,host=pop-os,topic=telegraf/host01/cpu value=100i 1653579153147395661
|
||||||
|
```
|
||||||
|
|
||||||
## About Topic Parsing
|
## About Topic Parsing
|
||||||
|
|
||||||
The MQTT topic as a whole is stored as a tag, but this can be far too coarse to
|
The MQTT topic as a whole is stored as a tag, but this can be far too coarse to
|
||||||
|
|
@ -95,7 +102,7 @@ tag values to be extracted from the MQTT topic letting you store the information
|
||||||
provided in the topic in a meaningful way. An `_` denotes an ignored entry in
|
provided in the topic in a meaningful way. An `_` denotes an ignored entry in
|
||||||
the topic path. Please see the following example.
|
the topic path. Please see the following example.
|
||||||
|
|
||||||
## Example Configuration for topic parsing
|
### Topic Parsing Example
|
||||||
|
|
||||||
```toml
|
```toml
|
||||||
[[inputs.mqtt_consumer]]
|
[[inputs.mqtt_consumer]]
|
||||||
|
|
@ -127,12 +134,59 @@ the topic path. Please see the following example.
|
||||||
test = "int"
|
test = "int"
|
||||||
```
|
```
|
||||||
|
|
||||||
## Example Output
|
Will result in the following metric:
|
||||||
|
|
||||||
```shell
|
```text
|
||||||
cpu,host=pop-os,tag=telegraf,topic=telegraf/one/cpu/23 value=45,test=23i 1637014942460689291
|
cpu,host=pop-os,tag=telegraf,topic=telegraf/one/cpu/23 value=45,test=23i 1637014942460689291
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Field Pivoting Example
|
||||||
|
|
||||||
|
You can use the pivot processor to rotate single
|
||||||
|
valued metrics into a multi field metric.
|
||||||
|
For more info check out the pivot processors
|
||||||
|
[here][1].
|
||||||
|
|
||||||
|
For this example these are the topics:
|
||||||
|
|
||||||
|
```text
|
||||||
|
/sensors/CLE/v1/device5/temp
|
||||||
|
/sensors/CLE/v1/device5/rpm
|
||||||
|
/sensors/CLE/v1/device5/ph
|
||||||
|
/sensors/CLE/v1/device5/spin
|
||||||
|
```
|
||||||
|
|
||||||
|
And these are the metrics:
|
||||||
|
|
||||||
|
```text
|
||||||
|
sensors,site=CLE,version=v1,device_name=device5,field=temp value=390
|
||||||
|
sensors,site=CLE,version=v1,device_name=device5,field=rpm value=45.0
|
||||||
|
sensors,site=CLE,version=v1,device_name=device5,field=ph value=1.45
|
||||||
|
```
|
||||||
|
|
||||||
|
Using pivot in the config will rotate the metrics into a multi field metric.
|
||||||
|
The config:
|
||||||
|
|
||||||
|
```toml
|
||||||
|
[[inputs.mqtt_consumer]]
|
||||||
|
....
|
||||||
|
topics = "/sensors/#"
|
||||||
|
[[inputs.mqtt_consumer.topic_parsing]]
|
||||||
|
measurement = "/measurement/_/_/_/_"
|
||||||
|
tags = "/_/site/version/device_name/field"
|
||||||
|
[[processors.pivot]]
|
||||||
|
tag_key = "field"
|
||||||
|
value_key = "value"
|
||||||
|
```
|
||||||
|
|
||||||
|
Will result in the following metric:
|
||||||
|
|
||||||
|
```text
|
||||||
|
sensors,site=CLE,version=v1,device_name=device5 temp=390,rpm=45.0,ph=1.45
|
||||||
|
```
|
||||||
|
|
||||||
|
[1]: <https://github.com/influxdata/telegraf/tree/master/plugins/processors/pivot> "Pivot Processor"
|
||||||
|
|
||||||
## Metrics
|
## Metrics
|
||||||
|
|
||||||
- All measurements are tagged with the incoming topic, ie
|
- All measurements are tagged with the incoming topic, ie
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue