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

CLI: Test tool #80

Closed kpetremann closed 7 months ago

kpetremann commented 7 months ago

Add an interactive test mode in CLI, to test the conversion of a topic+payload to a Prometheus metric.

Usage example

$ python ./exporter.py --test
topic: zigbee2mqtt/0x00157d00032b1234
payload: {"temperature":26.24,"humidity":45.37}

## Debug ##

parsed to: zigbee2mqtt_0x00157d00032b1234 {'temperature': 26.24, 'humidity': 45.37}
INFO:mqtt-exporter:creating prometheus metric: PromMetricId(name='mqtt_temperature', labels=())
INFO:mqtt-exporter:creating prometheus metric: PromMetricId(name='mqtt_humidity', labels=())

## Result ##

# HELP mqtt_temperature metric generated from MQTT message.
# TYPE mqtt_temperature gauge
mqtt_temperature{topic="zigbee2mqtt_0x00157d00032b1234"} 26.24
# HELP mqtt_humidity metric generated from MQTT message.
# TYPE mqtt_humidity gauge
mqtt_humidity{topic="zigbee2mqtt_0x00157d00032b1234"} 45.37