Thank you for reaching out to MongoDB about your question regarding
The .NET/C# driver exposes a wide variety of internal metrics via Eventing. This includes creation/destruction of connection pools, connections being added/removed from pools, connections checked in/out of pools, and more. For example, the wait queue is entered when
ConnectionPoolCheckingOutConnectionEvent is raised and exited when
ConnectionPoolCheckingOutConnectionFailedEvent is raised. A connection is active between
ConnectionPoolCheckedInConnectionEvent. You can keep track of the total number of connections by monitoring
One point to note. Connection pools are per cluster member, not per MongoClient. So if you have a 3 member replica set, you will have 3 connection pools, one for each node in the cluster. There is an additional monitoring connection outside of the connection pools using for Server Discovery and Monitoring (SDAM).
For an example of how to build a monitoring solution, you can take a look at the PerformanceCounterEventSubscriber in the source code. You can see how various counters are incremented and decremented in response to various driver events, which can then be forwarded onto whatever monitoring solution (potentially as simple as
Console.WriteLine for debugging purposes) you want to use. Note that this particular subscriber neglected to handle the
ConnectionPoolCheckingOutConnectionFailedEvent, which means that counts will not be accurate in the face of connection checkout timeouts.
Hopefully that gives you a starting point for diagnosing the issues that you are observing. Please let us know if you have any additional questions.