13

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?

Ghanima
  • 2,539
  • 1
  • 19
  • 46

2 Answers2

6

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)
Ghanima
  • 2,539
  • 1
  • 19
  • 46
1

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.

cogitoergosum
  • 1,091
  • 7
  • 18