3

I just want to know how many clients are actively connected to my mosquitto server. Or even better, get a list of client ids connected to my mosquitto server. I read some documentation suggesting the topic $SYS/broker/clients/connected will give this information. But this command yielded no response and no results:

mosquitto_sub -h myserver.myserver.myserver -p 9500 -t $SYS/broker/clients/connected -u "my-user" -P "my-password" --capath /etc/ssl/certs/

(I replaced myserver.myserver.myserver and my-user and my-password with actual values.) I verified the connection is working because if I publish a message to the same topic, the message appears.

How can I get a list of clients with active connection to my mosquitto server? Or at least a numeric count of active connections?

4

Bah I figured it out. I need to put single quotes around the topic so that $SYS isn't interpreted as a variable. So like this:

mosquitto_sub -h myserver.myserver.myserver -p 9500 -t '$SYS/broker/clients/connected' -u "my-user" -P "my-password" --capath /etc/ssl/certs/
1
  • 1
    You can accept your own answer if you like. :) Aug 12 at 7:20
2

This seems to work:

netstat -ntp | grep ESTABLISHED.*mosquitto

Which in my case outputs:

tcp        0      0 10.42.0.2:1883          10.42.0.18:56553        ESTABLISHED 448/mosquitto       
tcp        0      0 10.42.0.2:1883          10.42.0.19:54037        ESTABLISHED 448/mosquitto       
tcp        0      0 10.42.0.2:1883          10.42.0.11:49321        ESTABLISHED 448/mosquitto       
tcp        0      0 10.42.0.2:1883          10.42.0.15:48685        ESTABLISHED 448/mosquitto       
tcp        0      0 10.42.0.2:1883          10.42.0.12:57691        ESTABLISHED 448/mosquitto       
tcp        0      0 10.42.0.2:1883          10.42.0.13:56037        ESTABLISHED 448/mosquitto       
tcp        0      0 10.42.0.2:1883          10.42.0.17:40679        ESTABLISHED 448/mosquitto       
tcp        0      0 10.42.0.2:1883          10.42.0.16:39627        ESTABLISHED 448/mosquitto       
tcp        0      0 10.42.0.2:1883          10.42.0.14:33079        ESTABLISHED 448/mosquitto       

If one only cares about the total count:

netstat -natp | grep ESTABLISHED.*mosquitto | wc -l

prints

9

netstat arguments: -n to avoid getting host names for ip addresses (faster), -t for TCP instead of UDP and -p to display program names so we can filter using grep.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.