0

I want to monitor current connecton pool occupancy using .net mongo driver to produce stats each minute (like 5/MaxConnectionPoolSize is busy). But I can't see any option to do it in my driver (2.8.1). Is it even possible?

I've found some answers for the similar question for js client but sadly can't apply it to my situation.
How to get the number of connections used (and free) to the MongoDB (from a client perspective)?

IvanSorokin
  • 81
  • 11

1 Answers1

1

you can use this command:

db.serverStatus()['connections']
{
    "current" : 18,
    "available" : 999982,
    "totalCreated" : 2175,
    "active" : 8,
    "exhaustIsMaster" : 6,
    "awaitingTopologyChanges" : 6
}

to run it via the driver, you should use: var doc = db.RunCommand<BsonDocument>("{ serverStatus : 1 }");

dododo
  • 3,872
  • 1
  • 14
  • 37
  • it seems that it is a server side answer about open connections, not a client side I needed. I have 10 services, each has its own mongo client with maxPoolSize of 100 (default) and I need to know how much open connections in a connection pull of each client – IvanSorokin Sep 23 '20 at 11:42
  • in this case, you should log/calcualte it via the driver events: https://mongodb.github.io/mongo-csharp-driver/2.10/reference/driver_core/events/. See the available events: https://github.com/mongodb/mongo-csharp-driver/tree/master/src/MongoDB.Driver.Core/Core/Events – dododo Sep 23 '20 at 13:03
  • Big thanks! I think this is definitely what I am looking for. – IvanSorokin Sep 24 '20 at 07:19