kpetremann / mqtt-exporter

Simple generic MQTT Prometheus exporter for IoT working out of the box
https://hub.docker.com/r/kpetrem/mqtt-exporter
MIT License
103 stars 29 forks source link

Attach additional labels from message user properties #64

Closed mortenlj closed 8 months ago

mortenlj commented 9 months ago

Describe the solution you'd like In MQTTv5 it is possible to attach "user properties" to each message, which is simply a string=>string dictionary. It would be very cool if these properties could be added as labels on the associated metric either instead of the topic label, or in addition to it.

Additional context I have several devices that publish several metrics. Currently I encode device information (such as which room and which floor it is in) in the device name, which then becomes part of the topic name. As a result I have topics with names like homely/smoke_alarm_basement_hallway/networklinkstrength with a single value. It's probably possible to do some relabeling tricks to extract that information out to separate labels when ingesting into prometheus, but it would be so much easier if mqtt-exporter would just set the labels from user properties instead.

If this sounds like a good idea, and nobody beats me to it, I might attempt a PR for it.

kpetremann commented 9 months ago

Hi @mortenlj, I did not know MQTTv5 had this feature. This looks to be a very good idea!

I might attempt a PR for it I look forward to review it :)

Thanks!