Deploy Monika in different regions using Fly.io
This article has been updated on June 4th, 2024. Follow our Substack to get the newest updates about Monika and NEO Sense.
Have you ever wondered how to monitor your website performances from other countries such as Singapore, India, or Japan? Typically, you can spin up a new DigitalOcean digital droplet, install Node, install Monika using NPM, and run Monika with your Monika configurations.
Recently, one of our colleagues Nico Prananta told us about Fly.io. So, we tried using Fly.io and discovered that it has many regions covered. That got us thinking: “How about we use it to monitor our website performances so that we could simulate if our websites are accessed from other countries?”
This article will show you how to deploy a Monika instance in multiple regions using Fly.io. So, without further ado:
What is Fly.io?
Fly.io is a Platform-as-a-service for running full-stack apps and databases close to your users. Using Fly.io, you can deploy different kinds of apps such as Node, Go, Laravel, Python, and Dockerfile-based applications.
In this example, we will show you how to run Monika in Fly.io using Dockerfile deployments. First, we need to install Fly CLI.
If you are using macOS, you can install it via Homebrew by running this command in your terminal:
brew install flyctlIf you are using Linux, you can run this command in your terminal:
curl -L https://fly.io/install.sh | shIf you are using Windows, you can run this command in your Powershell terminal:
powershell -Command “iwr https://fly.io/install.ps1 -useb | iex
After installing the Fly CLI, the next step is to log in to Fly.io. You might need to sign up first by running fly auth signup
in your terminal to create an account. Otherwise, you can run fly auth login
in your terminal.
Both commands will open a browser, so make sure you are running in a GUI environment. Once you are authenticated, you can proceed to the next step.
Deploy Monika to Fly.io
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. 18 notification channels to this day have been integrated into Monika.
To install Monika, you can choose whether you want to use Node Package Manager (NPM), download binaries from the Monika release page, package managers such as Homebrew or Snapcraft, or a Docker image.
Before we get started, you need to create a Monika configuration. Monika uses a YAML file to define all the settings and configurations. You can find a sample configuration file in the repository called monika.example.yml or create your own at the Monika Config Generator website.
Let’s create a folder called flyio-monika
in your local machine. Then, navigate to the flyio-monika
and create two files: Dockerfile and monika.yml.
Let me explain a little bit about these two files:
- The
Dockerfile
file will pull the latesthyperjump/monika
image from the Docker Hub and will be running themonika.yml
file. - The
monika.yml
file is the Monika configuration file. - This Monika configuration sets up a probe for the website “reqres.in”. The probe requests the website’s URL and triggers an alert if the response time exceeds 1000 milliseconds. An incident will be triggered if the alert condition is met twice in a row, and a recovery notification will be sent when the alert condition is not met twice in a row.
Save these two files inside the flyio-monika
directory. Once that’s done, you can run fly launch
in the flyio-monika
directory. You will be prompted to enter a unique name and select a location for the app.
You can skip the PostgreSQL database setup, and proceed to deploy now. It will automatically create a file called fly.toml
and it may take up to five minutes to successfully deploy the app. Once that’s done, you can go to your Fly.io dashboard to see that Monika is now running:
We want to add more regions to deploy our Monika instance. So, we need to add a new region to the region pool. You can simply do so by running fly regions add [...regions]
in your terminal. You can see all the available regions on the Fly.io documentation page.
Once you add the Hong Kong region, it’s time to scale the Monika instance by running fly scale 2 --max-per-region 1
in your terminal. Then, check if the scaling works by running fly scale show
Alternatively, you can go to the Fly.io dashboard and navigate to the Monitoring menu. You will see that your app is now running in two regions.
Congratulations! You have deployed Monika instances in different regions using Fly.io!
Closing
Deploying Monika instances in different regions is very helpful because you can simulate how your website is being accessed by many users from various regions. With Fly.io, everything can be done using the fly scale
command.
If you’re having a problem 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.