Monitor your MongoDB instances using Monika

Denny Pradipta
Hyperjump Tech
Published in
3 min readOct 27, 2022
MongoDB logo

Monika v1.13.3 was released on October 17th, 2022. In this version, we have included the feature to monitor your MongoDB instances using Monika configurations.

Taken from the official website, MongoDB is a document database with the scalability and flexibility that you want with the querying and indexing that you need. Using Monika, you can check if your MongoDB instances are working by sending a simple query to check if it’s working or not.

This article will show you how to monitor your MongoDB instances using Monika. So, without further ado:

It’s game time!

Monitor your MongoDB instances

Monika is an open-source and free synthetic monitoring command-line application. Monika stands for “Monitoring Berkala”, which means “periodic monitoring” in Indonesian. With Monika, you can add as many websites or endpoints as you want to monitor. You can monitor several conditions such as service outages or slow services.

You can configure Monika to send notifications of the incidents on your services through your favorite communication tools like SMTP mail, WhatsApp (it’s free!), Microsoft Teams, Slack, and many more. There are 18 notification channels to this day that have been integrated into Monika.

To install Monika, you can choose either Node Package Manager (NPM), download binaries from the Monika release page, package managers such as Homebrew or Snapcraft, or a Docker image.

For demonstration purposes, let’s run a dockerized MongoDB instance by running the following command:

# Mongo without auth
docker run -d --name mongo-test-1 -p 27017:27017 mongo:latest

# Mongo with auth
docker run -d --name mongo-test-2 -p 28017:27017 -e MONGO_INITDB_ROOT_USERNAME=mongoadmin -e MONGO_INITDB_ROOT_PASSWORD=secret mongo:latest

Those commands will run two MongoDB instances: one in port 27017 without any authentication, and the other in port 28017 with username mongoadmin and password secret.

Running MongoDB containers

Once we have our MongoDB instances running, let’s create a Monika configuration:

In the configuration above, Monika will:

  • Use the Desktop notification channel
  • This configuration will monitor both MongoDB instances using two methods: One using the connection URI and the other using manual configuration.
  • Because there is no interval and alerts defined, it will automatically use Monika's default interval and alerts.

With that said, let’s try our configuration by running monika -c monika.yml in your terminal.

Monika probing MongoDB instances

From the screenshot above we can see that Monika can connect to the database. Next, let’s try to disable one of our MongoDB instances by running docker stop mongo-test-1 in another terminal window.

MongoDB notification alert

As you can see in the screenshot above, Monika notified us via Desktop notifications that some of the MongoDB instances cannot be reached. Congratulations! You can now monitor your MongoDB instances!

Closing

Aside from monitoring your endpoints, you should monitor all possible sources of incidents before it happens. Expect more upcoming client probing from us, so stay updated on our Medium!

If you’re having a problem with using Monika, don’t hesitate to create an issue on Monika’s Github Issue Page. If you like this article, don’t forget to clap and share this article with your friends!

That’s it for today, see you next time!

Hyperjump is an open-source-first company providing engineering excellence service. We aim to build and commercialize open-source tools to help companies streamline, simplify, and secure the most important aspects of their modern DevOps practices.

--

--

Denny Pradipta
Hyperjump Tech

Full-stack developer who loves to explore new technologies. Uses MongoDB, Express, React, and Node daily. Regularly writing for Hyperjump Technologies.