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
108 stars 30 forks source link

Support for nested MQTT messages #15

Closed The-JC closed 3 years ago

The-JC commented 3 years ago

Added support for more complex(nested) MQTT messages, as some devices publish nested contents (for example Tasmota). To handle this, the metrics are recursively get parsed, to extract all metrics from a message.

An example would be this MQTT message:

{
    "Time": "2021-10-03T11:05:21",
    "ENERGY": {
        "Total": 152.657,
        "Yesterday": 1.758,
        "Today": 0.178,
        "Power": 143,
        "ApparentPower": 184,
        "ReactivePower": 117,
        "Factor": 0.77,
        "Voltage": 235,
        "Current": 0.784
    }
}

It will parse into:

mqtt_ENERGY_Total
mqtt_ENERGY_Yesterday
mqtt_ENERGY_Today
mqtt_ENERGY_Power
mqtt_ENERGY_ApparentPower
mqtt_ENERGY_ReactivePower
mqtt_ENERGY_Factor
mqtt_ENERGY_Voltage
mqtt_ENERGY_Current
kpetremann commented 3 years ago

Thanks for the PR :)