Created
August 24, 2021 11:48
-
-
Save Deeptiman/e2eddfe6a449f284d59962e83ee6a9ce to your computer and use it in GitHub Desktop.
pool-monitor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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