Skip to content

Commit

Permalink
docs(inputs.mqtt_consumer): add pivot example to readme (#11195)
Browse files Browse the repository at this point in the history
(cherry picked from commit 5598a16)
  • Loading branch information
MyaLongmire authored and Sven Rebhan committed Jul 5, 2022
1 parent 357ee51 commit 73ae402
Showing 1 changed file with 57 additions and 3 deletions.
60 changes: 57 additions & 3 deletions plugins/inputs/mqtt_consumer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ and creates metrics using one of the supported [input data formats][].
# 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

The MQTT topic as a whole is stored as a tag, but this can be far too coarse to
Expand All @@ -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
the topic path. Please see the following example.

## Example Configuration for topic parsing
### Topic Parsing Example

```toml
[[inputs.mqtt_consumer]]
Expand Down Expand Up @@ -127,12 +134,59 @@ the topic path. Please see the following example.
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
```

## 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

- All measurements are tagged with the incoming topic, ie
Expand Down

0 comments on commit 73ae402

Please sign in to comment.