MongoDB Cluster Monitoring in Go

Monitoring Structures

The [mongo-go-driver] provides monitoring structures to gather information from the connection pool, mongo command queries, and server connection heartbeats in the MongoDB cluster.

1. Connection Pool Monitoring

  • The PoolMonitor monitors the MongoDB connection pool lifecycle using the pool event listeners.
  • In the following code snippet, the Pool Event listeners are triggered in a different case that will automatically get called whenever the MongoDB connection pool executes the lifecycle method.

2. Mongo Command Monitoring

  • The command monitor will trigger each mongo transaction with its success/failure events.
  • In the following code snippet, the CommandMonitor callback function gets triggered based on the mongo transaction results.

3. Server Monitoring

  • The ServerMonitor captures the multiple mongo server events that the client can listen to generate server heartbeat reports by reading the server monitoring structure.
  • The server heartbeat monitor analyzes the communication between the mongo client and the mongo cluster replica sets. The ServerMonitor structure provides a monitoring reporting structure of mongo server events and the mongo transactions success/failure records.
  • In this code snippet, the ServerMonitor callback method gets triggered for each mongo server event.

Monitoring API endpoint

The monitoring structure information is marshaled into a JSON array and the API endpoint responds to the client request for the go-live readiness monitoring information.

More about the topic: