Visualizing Monika Data with Prometheus and Grafana

Denny Pradipta
Hyperjump Tech
Published in
6 min readAug 24, 2021
Photo by Luke Chesser on Unsplash

This article is part two of the previous article: Connecting Monika with Prometheus

I know some people prefer to see logs, but some people also beg to differ. When you run Monika for a couple of hours, you may be overwhelmed with so many lines of logs. Another case is that when you want to present your Monika data to non-technical people of the team, most of the time they would respond “I don’t know what the logs mean, could you explain it to me?”

Some people understand better with visuals: Colors, graphs, and tables. With visuals, some people may understand the context easier than having to look at the humongous lines of logs. After we connected Monika with Prometheus, we can visualize our Monika data with Grafana.

What is Grafana?

Taken from their website, Grafana is an open source visualization and analytics software. It allows you to query, visualize, be alerted, and explore your metrics no matter where they are stored. In plain English, it provides you with tools to turn your time-series database (TSDB) data into beautiful graphs and visualizations. It will be used to visualize your Monika data that has been processed by Prometheus.

How to use Grafana with Monika and Prometheus?

If you have previously read our article about connecting Monika with Prometheus, you are halfway through the setup. If you haven’t read the article, well, you should.

Install Grafana

Let’s assume that you already have Monika and Prometheus installed and connected. The next step is we need to install Grafana. Head to the Downloads page and select which OS you are using.

Grafana Download Page

After you installed Grafana, open your web browser and go to http://localhost:3000/. The default HTTP port that Grafana listens to is 3000 unless you have configured a different port. It should show you the login page. On the login page, enter admin for username and password. After you are logged in, you will see the prompt to change your default password. Change your default password, and submit. You are now on the Grafana home page.

Grafana Dashboard

Configure the Data Source

Before we configure the data source, we need to run Monika and Prometheus. In case you forgot, here are the commands to run Monika and Prometheus both locally or using Docker:

# Run Monika
# If you're installing Monika locally

monika -c monika.json --prometheus 3001
# Or if you're using Docker
docker run --name monika \
-p 3001:3001 \
-v ${PWD}/monika.json:/config/monika.json \
--prometheus 3001 \
--detach hyperjump/monika:latest
# Run Prometheus
# If you're installing Prometheus locally

./prometheus --config.file=prometheus.yml
# Or if you're using Docker
docker run -d --name prometheus \
-p 9090:9090 \
-v <PATH_TO_prometheus.yml>:/etc/prometheus/prometheus.yml \
prom/prometheus --config.file=/etc/prometheus/prometheus.yml

Back to the Grafana home page. On the left sidebar, hover the gear icon and select the Data Source option. Add a new data source by clicking the blue “Add data source” button. Then, select Prometheus as your data source.

Prometheus data source

If you are following the instructions from the previous article, you are running Prometheus in port 9090. Fill out the URL with http://localhost:9090 and click the Save and Test button. It should display a toast notification telling that the data source has been updated.

Successfully set the data source.

Creating the Dashboard

After the data source has been successfully added, hover over the plus icon sub-menu and select the Dashboard option. And then, click the “Add an Empty Panel” area. We are now going to create a probe status code information panel.

Add an Empty Panel

You are now on the edit panel page. In the right top section of the page, change the “Time Series” dropdown to “Stat”. Then, navigate to the metrics browser input field, type monika_request_status_code_infoand press Shift + Enter. After that, on the right sidebar, change the Panel Title to “Probe Status Code” and scroll down to the Threshold section. Set the color red threshold to 500. Now it should look like this:

Probe Status Code

Apply the changes, and we are halfway done. Next, we are going to create another panel for monitoring the average response time per 5 minutes.

Create another panel in the current dashboard. Navigate to the metrics browser input field, type this in one line, and press Shift + Enter:

rate(monika_request_response_time_seconds_sum[5m]) / rate(monika_request_response_time_seconds_count[5m])

After that, on the right sidebar, change the Panel Title to “Probe Average Response Time”. Then on the right sidebar, scroll down to the “Standard Options” section and change the unit to “Milliseconds”. Apply the changes, and you’re done!

Average Response Time per 5 minutes

If you had trouble while doing all of the above, you can check out the recorded version below (Don’t forget to turn on subtitles/closed captions).

Visualize Monika data with Prometheus and Grafana

Conclusion

The final result

Grafana is an open-source analytics software that can be used altogether with Monika and Prometheus. You can run Monika to check if your website is down periodically, export the data to Prometheus, and visualize the data using Grafana.

There is so much to explore with Monika, Prometheus, and Grafana. What I demonstrated is only the tip of the iceberg. You may also be interested in experimenting with what data you could query in Grafana using PromQL, check out the PromQL cheat sheet as this helps me a lot when writing this article.

If you haven’t heard of Monika, Monika is an open-source and free synthetic monitoring command-line application. The name Monika stands for “Monitoring Berkala”, which means “periodic monitoring” in the Indonesian language.

With Monika, you can add as many websites as you want to monitor. You can monitor several conditions such as service outages or slow services. Also, you can configure Monika to send notifications of the incidents on your services through your favorite communication tools like SMTP mail, Telegram, WhatsApp (It’s free!), etc.

Check out our repository in Github where you can request features and report an issue/bug below:

Thank you for reading this article. Time to show off to my boss with my beautiful graphs.

See you next article!

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 its 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.