Microservice Monitoring with Grafana & Prometheus

Monitoring Spring Boot Application using Prometheus and Grafana

Sajith vijesekara
Enlear Academy

--

When Dealing with multiple micro-services it is always better to monitor the systems using a monitoring tool. Here I am going to explain how we can monitor spring boot applications using Prometheus and Grafana.

What is Prometheus?

Prometheus is an open-source monitoring system that helps to periodically monitor the JVM Based systems.

What is Grafana?

Grafana is a tool that can inject various data sources and display them in a comprehensive graphical experience. It supports various data sources like ELK, Prometheus, Graphite. And It also supports sending alerts base on different conditions.

First Create the Spring microservice and add enable the actuator endpoints for the module.

In Spring web flux have to explicitly enable actuator endpoint. To do that have to add the following configuration application.yml

actuator configs

After that, once the spring boot application started it will show the exposed Prometheus endpoint.

actuator details

As the Next step create a docker image from the spring boot microservice.

The next step is to start Prometheus API Server. To-Do that needs to create a separate config for the Prometheus server. create a file called “prometheus.yml‘’.

The next step is to start to spring boot Microservice, Prometheus and grafana instances. for that here using the docker-compose to start all the modules.

docker compose config file

Once all the modules are started can verify the instance is available in Prometheus dashboard.

url : http://localhost:9090/graph

search by “process_cpu_usage”

After all, module startup go to grafana dashboard and setup data source.

add the correct Prometheus URL in config.

verify the Prometheus setup.

The final step is to create a dashboard panel and view the analytics.

view cpu usage of the micro service

Conclusion

To view the JVM statistics in grafana needs to first enable the actuator and enable the Prometheus endpoint for the Prometheus server. The next step is to set up Prometheus and open Prometheus as the data source in grafana.

I really hope you will understand the concepts of setup monitor tools integration in JVM-related frameworks.

--

--

Technical Lead. Passionate about cloud computing & web security | Freelance Mobile Developer| CKAD | AWS Community Builder 🇱🇰