Closed runningman84 closed 2 years ago
Sure, I'll have a look
It seems by default there is no client_id generated. See here
if client_id == "" or client_id is None:
if protocol == MQTTv31:
self._client_id = base62(uuid.uuid4().int, padding=22)
else:
self._client_id = b""
Also, I did not find a clean way to get the client id, as it is a private attribute of client object.
Do you need to have the client id auto generated, or do you want to specify it manually?
I would specify it manually using an ENV variable... if the variable is not present the client_id can be auto generated
ok, I'll add the possibility to specify the client id, and I'll expose it in the metrics if existing.
If the variable is not present the client_id can be auto generated
According the documentation, when client-id is empty, this is up to the MQTT broker to generate it. But the broker does not seem to send back the client-id to the client. In debug mode, client._client_id remains empty even during message processing.
If I force the client-id auto generation on client side, I would have to handle all possible issues such as client id already used.
Yes just leave the id empty and let the server auto generate something...
But the broker does not seem to send back the client-id to the client.
Confirmed here: https://github.com/eclipse/paho.mqtt.python/issues/237#issuecomment-336069672 :
No, if the server generate the clientid then it is not send to client.`
It looks like the behavior is fixed in MQTT v5: https://github.com/eclipse/paho.mqtt.python/issues/237#issuecomment-885269826 But default protocol in python MQTT client library is MQTT3.1.1.
I'll try with an option to choose the MQTT 5 version. If it is working, we will be able to get back the id generated by the broker and to expose it in Prometheus.
would it work for you? https://github.com/kpetremann/mqtt-exporter/pull/26. Feel free to test.
I still need to add some functional tests before merging it.
looks good
Code merged
it would be helpful to see the client_id...
The underlying python module seems to support that.