Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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