Skip to content

Instantly share code, notes, and snippets.

@Deeptiman
Created August 24, 2021 11:55
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/49b6d65ccc77e3f0e32c948de399a72a to your computer and use it in GitHub Desktop.
Save Deeptiman/49b6d65ccc77e3f0e32c948de399a72a to your computer and use it in GitHub Desktop.
server-monitor
serverMonitor := &event.ServerMonitor{
ServerHeartbeatStarted: func(evt *event.ServerHeartbeatStartedEvent) {
// Started event triggered when connection heartbeat prepares to start the connection lifecycle
// in the mongo cluster
ServerHeartbeatStartedEvent struct {
ConnectionID string // mongo connection ids [host-ids]
Awaited bool // If the connection is awaiting
}
},
ServerOpening: func(evt *event.ServerOpeningEvent) {
// Opening event triggered when connection heartbeat started opening the socket
ServerOpeningEvent struct {
Address address.Address // mongo connection host address
TopologyID primitive.ObjectID // mongo cluster topology unique ID
}
},
ServerHeartbeatSucceeded: func(evt *event.ServerHeartbeatSucceededEvent) {
// Succeeded event triggered when connection heartbeat succeeded in the mongo cluster
ServerHeartbeatSucceededEvent struct {
DurationNanos int64
Reply description.Server // description of server connection node in the cluster
ConnectionID string // mongo connection ids [host-ids]
Awaited bool // If the connection is awaiting
}
},
ServerHeartbeatFailed: func(evt *event.ServerHeartbeatFailedEvent) {
// Failed event triggered when connection heartbeat gets failed in the mongo cluster
ServerHeartbeatFailedEvent struct {
DurationNanos int64
Failure error // error message for connection heartbeat failure
ConnectionID string // mongo connection ids [host-ids]
Awaited bool // If the connection is awaiting
}
},
ServerClosed: func(evt *event.ServerClosedEvent) {
// Close event triggered when the server is closed
ServerClosedEvent struct {
Address address.Address // mongo connection host address
TopologyID primitive.ObjectID // mongo cluster topology unique ID
}
},
}
client, err := mongo.NewClient(options.Client().
ApplyURI("mongodb://<username>:<password>@localhost:27017").SetServerMonitor(serverMonitor))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment