Broker Mosquitto has group of topics in which he publishes various information about his work. By subscribing to these topics, we can find out, for example, what the number of subscribers are now, or how many messages have been published or received since the start of the server.
At the beginning of the check the version has our broker. This information has been published in the to
pic $SYS/broker/version to subscribe enough to execute the command:
mosquitto_sub -t '$SYS/broker/version'
If you have previously set permissions for users, you must also provide your login and password. The details described in the previous article.
This command will result in a message containing Mosquitto versions:
Another useful topic is $SYS
/broker/subscriptions/count, Mosquitto publishes the current number of subscribers.
Note that the initial published message contains information about the number of subscribers before the command is called, and the next contains only the current value.
The frequency of publishing system topics ($SYS) depends on the
sys_interval parameter, which determines how often (in seconds) we want the server to publish the information. To change the settings we need to edit the file mosquitto.conf. Open the terminal and execute the command:
And then in the open file we add line:
Save the file (Ctrl + O) and close the editor (CTRL + x), and reset the broker Mosquitto:
sudo /etc/init.d/mosquitto restart
With this setting, although the value of the parameter is changed, it will not be published in the topic until is no longer 10 seconds from the previous publication.
This solution can be useful when you do not need data all the time, so there is no need to additionally load the computer on which it works Mosquitto. For example, entering a value of 86400 (seconds) will cause the data to be published once a day.
When you set the
sys_interval value to 0, no data will be published. This is how to disable the system topics.
All information is published by the broker with the
-r parameter so that the new subscriber receives the last-published message during the call.
In the article I presented only a fragment of the possibilities of system topics, they are all described on the Mosquitto documentation page.