mosquitto icon indicating copy to clipboard operation
mosquitto copied to clipboard

Add subscription information to mosquitto_db_dump

Open gw1urf opened this issue 4 years ago • 4 comments

I sometimes need to use mosquitto_db_dump --client-stats to debug why the database has grown large. Usually it's because a client with a persistent subscription has gone away, never to come back. In that case, I need to know the topic information so I can unsubscribe from it.

At present mosquitto_db_dump shows the number of subscriptions, but not their topics. Please find attached a patch which adds that information to the --client-stats output.

Here's some example output with the patch applied:

# mosquitto_db_dump --client-stats mosquitto.db 
SC: 0 SS: 0 MC: 0 MS: 0   client_id_1
SC: 6 SS: 491 MC: 10 MS: 3493   client_id_2 (dhcp/#, healthcheck/#, 433/db, 433/#, hive/json, webcam/weather)
SC: 3 SS: 269 MC: 0 MS: 0   client_id_3 (webcam/front/#, webcam/front/01/0/0/2/1/#, webcam/front/01/#)

db_dump.patch.txt

gw1urf avatar Feb 03 '21 10:02 gw1urf

That sounds reasonable to me.

ralight avatar Feb 03 '21 15:02 ralight

I sometimes need to use mosquitto_db_dump --client-stats to debug why the database has grown large. Usually it's because a client with a persistent subscription has gone away, never to come back. In that case, I need to know the topic information so I can unsubscribe from it. At present mosquitto_db_dump shows the number of subscriptions, but not their topics. Please find attached a patch which adds that information to the --client-stats output. Here's some example output with the patch applied:

# mosquitto_db_dump --client-stats mosquitto.db 
SC: 0 SS: 0 MC: 0 MS: 0   client_id_1
SC: 6 SS: 491 MC: 10 MS: 3493   client_id_2 (dhcp/#, healthcheck/#, 433/db, 433/#, hive/json, webcam/weather)
SC: 3 SS: 269 MC: 0 MS: 0   client_id_3 (webcam/front/#, webcam/front/01/0/0/2/1/#, webcam/front/01/#)

db_dump.patch.txt

how to use the command "mosquitto_db_dump".I have an error that I cannot find the command mosquitto_db_dump. My mosquitto version 1.4.5

bahientn9x avatar Feb 22 '21 02:02 bahientn9x

@bahientn9x If you're compiling by yourself, it's in the apps/db_dump directory. It's not something that is typically provided in binary installations though.

ralight avatar Feb 25 '21 14:02 ralight

You can connect to the server with mosquitto_sub with clean_session true, and with the same client_id, and the subscriptions will all be removed.

jsaak avatar Mar 05 '21 06:03 jsaak