Count open socket and channel connections in a Phoenix application

1.5k views Asked by At

Is there a relatively simple, documented way in a Phoenix application to read how many active sockets and channels are currently open at any given time? And more specifically, is it possible to filter this data by topic and other channel connection metadata?

My use case is for analytics on active connections to my backend.

Thanks for any suggestions!

1

There are 1 answers

8
Aleksei Matiushkin On

You are looking for Phoenix.Presence. From the documentation:

Provides Presence tracking to processes and channels.

This behaviour provides presence features such as fetching presences for a given topic, as well as handling diffs of join and leave events as they occur in real-time. Using this module defines a supervisor and allows the calling module to implement the Phoenix.Tracker behaviour which starts a tracker process to handle presence information.

Basically, you are supposed to implement Phoenix.Presence behaviour (the almost ready-to-go example is there in docs,) and Phoenix.Tracker according to your needs.