Beautifying Prometheus metrics using Grafana
This is a buildup on my previous articles
I have always maintained that Prometheus has limited metrics visualization. It has good enough visualization that leaves you wanting for more.
Grafana covers visualization well. And on top of that - adds alerting capabilities too.
In our company, we use the Prometheus + Grafana stack to monitor the Kubernetes cluster, Spring Boot applications, Infrastructure applications like Gitlab, Jenkins, etc.
What is covered
This article covers
- installing Grafana as a Docker container
- connecting to Prometheus
- using an existing dashboard
- creating a new dashboard to monitor endpoints
Installing Grafana as a Docker container
docker run --detach \--publish 3000:3000 \--name grafana \grafana/grafana
Nothing fancy here. But if you wish to go fancy - then here is the documentation.
Open http://localhost:3000/login to login. Use admin/admin to login. That is the default id-password.
My home page looks like this:
Connecting to Prometheus
- On the home page, there is a box "Data Sources". Click it.
- Select Prometheus.
- Select URL as http://docker.for.mac.host.internal:9090.
- Note: instead of localhost, I use 'docker.for.mac.host.internal' because Grafana is running as a docker container. And to access my laptop's network, I need to use a special DNS name. Or stackoverflow.
- Click "Save and Test" button.
My configurations look like this:
Using an existing Dashboard
Grafana has a big community. There are many pre-built dashboards that we can use. One of the most widely used is "JVM Dashboard".
Step 1: Choose a Dashboard
- Open https://grafana.com/grafana/dashboards. This page allows us to search among dashboards.
- Scroll down until you find a filter panel on the left side of the page.
- Select "Name" as "JVM, and "Data Source" as "Prometheus". Now choose the one you like.
- I choose the one by the author "mweirauch". At the time of writing this article, there are 57822 downloads. Hence I trust this one.
- Select the dashboard you want. It takes you to the dashboard description page. Copt its URL. Mine looks like this: https://grafana.com/grafana/dashboards/4701.
Step 2: Install selected Dashboard
- On the Home page, on the left menubar, there is a + symbol. Hover over it and select "Import". We shall try to import an existing Dashboard created by the community.
- Put the URL (of the selected dashboard) and click "Load"
- You should see details about the selected dashboard.
- In the "Prometheus" dropdown (towards the bottom of the form), select the DataSource you had created earlier. I had named mine "Prometheus". So I select that.
- Click "Import"
And ta-da!
I see my dashboard.
Create a new Dashboard
Someone else's Dashboard is his view of his application. For your application, you will want to create something your own.
I wish to see what's happening with my /chance endpoint (from the previous article).
- Go to home page
- On left menubar, hover over + symbol. Select Dashboard.
- Click on "Add an empty panel"
- This opens up a blank graph with a form at the bottom. Notice that the textbox needs a Prometheus Query. Use the query from the previous article
- http_server_requests_seconds_count{method="GET", uri="/chance"}
- And click "Apply". This button is placed in the top-right corner.
- Don't forget to save your dashboard - click on the save icon on the top-right of the page.
Ta-da!
My dashboard leaves me wanting more - but it is a good start.
Conclusion
Grafana spits out beautiful charts. It has alerting module too. Talking about alerts is beyond scope of this article.
I would go ahead to say that Grafana makes Prometheus more usable.
Comments
Post a Comment