MongoDB Cluster Monitoring in Go

Monitoring Structures

Official Monitoring Packages

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

Run the mongo monitoring POC

  • Conn1: Connection pool created to perform “Ping” request to check mongo server connection status. After receiving the “Pong” response connection instance returned to the pool.
  • Conn2: connection pool created to “ListDatabaseNames” in the MongoDB cluster. After receiving the list of database names, the connection instance returned to the pool.
  • The pool monitor shows connections instances created and returned to the pool.
  • The heartbeat records show the connection instances created in the pool and performed the server connection heartbeat lifecycle.
  • As there is no failed heartbeat in this connection flow, so ServerHeartbeatFailed JSON array remains empty.
  • The command monitor shows, there are two mongo commands “ping”, “listDatabases” that have been executed in the cluster.
  • cmdMonitorStart JSON array shows the number of commands attempted to execute in the cluster and cmdMonitorSucceed JSON array shows the corresponding succeeded commands with their requestIDs.
  • In this case, there are no failed mongo commands, so the cmdMonitorFailed JSON array remains empty.

Monitoring failure scenarios

  • In case the MongoDB cluster is down serverHeartbeatFailed JSON array will show connection failure records.




Working on various software development projects, [Android, Go, Blockchain, Node.js, MongoDB, JavaScript, Kubernetes, Docker]

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Division & Dynamic Programming

The start of my programming journey

Avoid 🤦‍♂️ — use Elixir 😻

Medium Clap Animation in Android

- For learnability, consider making "CMake" hyperlink to


Deployment of Deep Learning Models in AWS using AWS Lambda + AWS API gateway + AWS Elastic File…

C Programming for Beginners continued………(4th part)

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Deeptiman Pattnaik

Deeptiman Pattnaik

Working on various software development projects, [Android, Go, Blockchain, Node.js, MongoDB, JavaScript, Kubernetes, Docker]

More from Medium

ELK Enhanced Search Operations | Part6

Continuous Build and Deployment of Go Applications with Google Cloud Build

Track and log slow nginx requests

How to Setup a Scalable Ultra Low Latency Streaming Cluster in AWS — Ant Media Server