Skip to content

Instantly share code, notes, and snippets.

@Deeptiman
Created August 24, 2021 11:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Deeptiman/e2eddfe6a449f284d59962e83ee6a9ce to your computer and use it in GitHub Desktop.
Save Deeptiman/e2eddfe6a449f284d59962e83ee6a9ce to your computer and use it in GitHub Desktop.
pool-monitor
poolMonitor := &event.PoolMonitor{
Event: func(e *event.PoolEvent) {
switch e.Type {
case event.PoolCreated:
// mongo-connection pool creation events.
connPoolCreated++
case event.GetSucceeded:
// succesful mongo connection established by the pool
connSuccess++
case event.ConnectionClosed:
// mongo-connection gets closed
connClosed++
case event.ConnectionReturned:
// connection instance returns to the pool after completing a mongo transaction.
connReturned++
case event.PoolCleared:
// PoolCleared event will remove all the connections from the pool
connPoolCleared++
}
},
}
client, err := mongo.NewClient(options.Client().
ApplyURI("mongodb://<username>:<password>@localhost:27017").SetPoolMonitor(poolMonitor))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment