I've used MongoDB in a number of projects over the years. One thing I've often found I need is a quick way to see the topology and status of a cluster. I recently cleaned up a small utility I've used over the years to
check the status of a cluster.
The animation below shows the tool monitoring a sharded cluster while I make changes in realtime - adding a node to a replicaset, stepping down a primary and shutting down a replicaset node:
The view updates real time, which makes it very helpful if you are performing server administation such as reconfiguring a replicaset or sharded cluster. As you make changes through the shell, you can see how the cluster responds.
For long term monitoring, of course you are going to need dedicated solutions to understand cluster health, infrastructure health and so on. But while you are making changes to your cluster and want to keep a very close eye on the topology real-time, I've found this tool to be amazingly useful!
Installing the CLI
The CLI is installed with
npm install -g mongo-monitor-cli
Connecting to a Cluster
Connect to a cluster by providing a connection string. The tool uses
mongo-connection-string to parse the connection string, so you can be flexible with the input:
# Connect to a local instance
# Connect to a remote replicaset, authenticated
Once a connection is established, the tool will periodically check the status of the cluster. If the cluster is sharded, it will also inspect each individual replicaset.
Here's the kind of output you might get from a replicaset:
The name of the replicaset is shown, along with each member. The status of each member is also shown, updating automatically every second.
This is convenient when administering replicasets, stepping down a master, adding or removing nodes and so on.
Sharded Cluster Status
When connecting to a sharded cluster, you will get output like this:
Each shard is shown, along with the details of the replicaset which make it up.
Keeping a view like this open is useful when administering sharded clusters, adding or removing shards, desharding, updating the replicasets which make up shards and so on.
If you like the tool, check out the code and feel free to make pull requests with additions! There are a few issues on the project already, and there are all sorts of features I'd love to add but haven't had the time, such as:
- Being able to see the lag for replicaset members, to see if secondaries are falling behind
- Being able to perform replicaset operations directly from the tool
- Showing the priorities of nodes if they are not the default
All ideas are welcome, let me know in the comments or repo, and share the tool if you find it useful!