This article is a step-by-step guide on how to migrate from a Monolith to Microservices
Containers are widely used today from development to production. However, a
docker stats in ssh does not allow you to correctly assess your production environment. We will therefore see how to meet this monitoring need for containers in production.
We will discuss several technologies to meet this need:
- cAdvisor, solution made open-source by Google which allows all container metrics to be exposed.
- Prometheus, open-source solution for time series oriented databases.
- Grafana, open-source solution for easily configurable dashboards which will help draw nice graphs.
Resource: ctop allows you to view
docker statsinfo in
The stack that we are going to see works like this:
cAdvisorwill expose the
http://cadvisor:8080/metricsendpoint with all the metrics of the containers at a given time
Prometheuswill query every
xseconds the endpoint from cAdvisor and store metrics in its database.
Grafanawill display metrics from Prometheus in the form of graphs.
Before you begin, make sure you have
docker-compose installed. My versions for writing this article are:
For starters, we're going to quickly install an app, take for example Api Platform.
We now have access to the documentation for the API you just installed.
We are going to add
Resource: you can find
We can now access
This already allows us to see briefly the metrics of our containers.
However, this solution alone is not configurable enough and cannot fully meet our needs.
Let's begin by installing
And let's add the configuration file
prometheus.yml into the
We can notice the
cadvisor scraping job on the
cadvisor: 8080 endpoint. Prometheus will always scrape according to the following scheme:
For configuration, the
/metrics is implied.
We can restart
We can see that the jobs we configured are up. That is to say that
Prometheus has managed to scrape the metrics from
We are going to install
docker-compose one last time.
Access: Default access codes for Grafana are admin admin
Let's start by adding our
Data Sources. Let's go to http://localhost:3000/datasources/new and add the host of our
Grafana can access our
Prometheus all we have to do is create a new dashboard. To save time we will import it directly.
Let's import this new dashboard http://localhost:3000/dashboard/new?editview=import∨gId=1 and put the template id
193. Once done, we can go to our dashboard.
We can now see the system metrics of our containers, like the consumption
ram for each of them.
Depending on your needs, you can create more specific dashboards with the information you need.
Prometheus, there are many
exporters to be able to retrieve even more metrics like for example for
You can also create an
exporter yourself as long as it exposes metrics on an
/metrics endpoint or even exposes business metrics from your application.
Resource: you can find the business metrics exposure in a Java application, as explained in this article http://blog.xebia.fr/2017/07/28/superviser-mon-application-play-avec-prometheus