I am running emqttd (emqtt.io). I would like to monitor clients connecting and disconnecting from a separate process that would be subscribing to a system topic where birth and will messages are posted. What is the right way to do that?
2 Answers
I would like to monitor clients connecting and disconnecting from a separate process that would be subscribing to a system topic where birth and will messages are posted.
emqtt's User Guide shows a system topic that offers some Broker Statistics, i.e. $SYS/brokers/${node}/stats/clients/count
provides the count of current connected clients. Note that this will not list any specifics about the connected clients - so I take it that is not what is needed here.
Last will (LWT, Last Will and Testament) messages are otoh not a system topic but a regular topic as set up by the client during connect. If you want to monitor that topic simply subscribe to it. Note however that LWT messages are discarded if a client disconnects gracefully by sending a DISCONNECT message (see hiveMQ blog, great read btw).
emqtt's User Guide presents a better way to monitor connecting and disconnecting clients:
The
./bin/emqttd_ctl
command line could be used to query and administrate the EMQ broker (not working on Windows).
I think that monitoring clients list
- list all MQTT clients - and clients show <ClientId>
- show a MQTT Client - are most helpful here. The planned separate process to monitor clients therefore does not need to subscribe to the broker but simply utilize ./bin/emqttd_ctl
instead.
$ ./bin/emqttd_ctl clients list Client(mosqsub/43832-airlee.lo, clean_sess=true, username=test, peername=127.0.0.1:64896, connected_at=1452929113) Client(mosqsub/44011-airlee.lo, clean_sess=true, username=test, peername=127.0.0.1:64961, connected_at=1452929275)
-
Very useful. Thanks for taking the time. emqttd_ctl might provide a partial solution but, having a pubsub at our disposal, I would have hoped that you could use that mechanism to create alerts. I guess it is something I could still enforce by requiring clients to publish birth and will messages. Commented Jan 14, 2017 at 5:33
Well, not sure about the birth message and LWT (Last Will and Testament) is optional as per the spec. So, you wouldn't necessarily receive messages unless you had your broker customised to such requirements.
-
LWT is the broker acting on behalf of the disconnected client. Implementing that is not optional for the broker. It's merely optional for the client to set up a last will topic.– Ghanima ♦Commented Jan 11, 2017 at 18:49
-
That is what I meant. The client may not it send as part of connect packet. Commented Jan 11, 2017 at 19:05