How do I find out who is connected to ActionCable?

b264 picture b264 · Mar 19, 2016 · Viewed 9.2k times · Source

I have seen ActionCable.server.open_connections_statistics, ActionCable.server.connections.length, ActionCable.server.connections.map(&:statistics), ActionCable.server.connections.select(&:beat).count and the like, however this is only "per process" (server, console, server worker, et cetera). How do I find out everyone who is subscribed to ActionCable at this time? This should return the same value on any Rails process in each environment (development, staging, production). So for example, in development console you can also see the connections on the development server since they, in theory, use the same subscription adapter (redis, async, postgres).

Rails 5.0.0.beta3, Ruby 2.3.0

related ActionCable - how to display number of connected users?

Answer

Razor picture Razor · Mar 26, 2016

If using redis you can see all the pubsub channels.

[2] pry(main)> Redis.new.pubsub("channels", "action_cable/*")
[
    [0] "action_cable/Z2lkOi8vbWFvY290LXByb2plL3QvUmVzcG9uXGVyLzEx",
    [1] "action_cable/Z2lkOi8vbWFvY290LXByb2plL3QvUmVzcG9uXGVyLzI"
]

This will show all websocket connections for all the Puma workers together. And if you have multiple servers it will probably show those here too.