Count idle/used Ecto repo connections in real-time

Hi, I wonder if there is a reliable way to count/monitor used database connections for given repo. One of the ideas tried so far was checking Ecto.Repo.Registry :ets table and then extracting size of DBConnection.ConnectionPool.Queue for specific repo. Please let me know if this method can be considered as reliable.

You could possibly use a telemetry handler to increment and decrement a counter as queries start and stop? The counter could be state held in a GenServer, or maybe ETS.

Thanks, as far as I understand data from telemetry can be used to count only DB queries. I want to monitor idle/used postgres connections too. However, not sure if there is a reliable way to do that. I guess a contributor (or someone with a deep knowledge about ecto/db_connection) would be able to explain that.