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 UserProperties as labels to metrics when using MQTTv5 protocol #65

Closed mortenlj closed 8 months ago

mortenlj commented 9 months ago

Fixes/Implement: #64

Description: When using MQTTv5, attach any UserProperties from the message as labels on the exposed metrics.

kpetremann commented 9 months ago

LGTM, thanks!

janpfischer commented 8 months ago

I believe this might cause some problems on my side. Just updated from the last version which was running completely fine. The new version exit with the following error. I believe this might be related to this PR, because the error message is close to the topic of this PR.

Traceback (most recent call last):
  File "/opt/mqtt-exporter/exporter.py", line 5, in <module>
    main()
  File "/opt/mqtt-exporter/mqtt_exporter/main.py", line 436, in main
    client.loop_forever()
  File "/usr/local/lib/python3.10/site-packages/paho/mqtt/client.py", line 1756, in loop_forever
    rc = self._loop(timeout)
  File "/usr/local/lib/python3.10/site-packages/paho/mqtt/client.py", line 1164, in _loop
    rc = self.loop_read()
  File "/usr/local/lib/python3.10/site-packages/paho/mqtt/client.py", line 1556, in loop_read
    rc = self._packet_read()
  File "/usr/local/lib/python3.10/site-packages/paho/mqtt/client.py", line 2439, in _packet_read
    rc = self._packet_handle()
  File "/usr/local/lib/python3.10/site-packages/paho/mqtt/client.py", line 3033, in _packet_handle
    return self._handle_publish()
  File "/usr/local/lib/python3.10/site-packages/paho/mqtt/client.py", line 3327, in _handle_publish
    self._handle_on_message(message)
  File "/usr/local/lib/python3.10/site-packages/paho/mqtt/client.py", line 3570, in _handle_on_message
    on_message(self, self._userdata, message)
  File "/opt/mqtt-exporter/mqtt_exporter/main.py", line 388, in expose_metrics
    additional_labels = _parse_properties(msg.properties)
  File "/opt/mqtt-exporter/mqtt_exporter/main.py", line 368, in _parse_properties
    for key, value in properties.UserProperty
AttributeError: 'Properties' object has no attribute 'UserProperty'. Did you mean: 'readProperty'?
Stream closed EOF for home-automation/zigbee2mqtt-0 (exporter)
kpetremann commented 8 months ago

hello @janpfischer, Thanks for reporting this bug. I'll post a quick fix for this.

In the meantime let's do the follow-up in a dedicated issue here: #66