The MQTT brokers (specifically mosquitto), tend to send some metadata about the broker itself, the clients connected and more.
The information (metadata) we grab from the broker can be grabbed through a successful subscription to certain special topics. Those topics are located within the $SYS hierarchy. There are quite a lot of them, but we mainly focus on 9 important topics.
To see the broker information, first create a successful connection using the connect
command, then use the system_info
command as follows:
localhost:1883 >> system_info
+--------------+--------------------------+
| Property | Value |
+--------------+--------------------------+
| timestamp | 2018-04-11 06:55:09-0400 |
| uptime | 699152 seconds |
| maximum | 228887 |
| count | 582668 |
| disconnected | 225697 |
| total | 228882 |
| connected | 3185 |
| version | mosquitto version 1.4.15 |
+--------------+--------------------------+
The topics we are focusing our plugin on are the following (the description was taken directly from the mosquitto documentation):
The version of the broker
The timestamp at which this particular build of the broker was made.
The amount of time in seconds the broker has been online.
The total number of subscriptions active on the broker.
The number of currently connected clients.
The number of disconnected persistent clients that have been expired and removed through the persistent_client_expiration option.
The total number of persistent clients (with clean session disabled) that are registered at the broker but are currently disconnected.
The maximum number of clients that have been connected to the broker at the same time.
The total number of active and inactive clients currently connected and registered on the broker.