Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to expose metrics to Prometheus from a Java (Spring boot) application

My Spring-Boot application simply has a counter metric. I just don't know how to send this information to Prometheus. I am using Maven (build tool) and Spring Boot (Java).

like image 569
kramsiv1234 Avatar asked Nov 29 '17 18:11

kramsiv1234


People also ask

How do you expose Prometheus metrics in spring boot?

Start your application, and send an HTTP get request to http://localhost:8080/actuator/prometheus . You will see all of the metrics being exposed. If you don't see your custom metric, make sure that you have triggered the code to be executed. The metric won't appear until the timer has recorded at least once.

How do I monitor my spring boot application?

The first part of monitoring Spring Boot applications is choosing a metrics database. By default, Spring Boot will configure a Micrometer metrics registry in every application. This default implementation collects a pre-defined set of application metrics such as memory and CPU usage, HTTP requests, and a few others.


1 Answers

Prometheus, like Graphite, is a time-series storage engine.

Grafana can then query Prometheus to generate graphics and alerts.

https://prometheus.io/docs/introduction/faq/

As the documentation cites, Prometheus, unlike other metrics storage systems, uses a (debatable) "pull" model.

This means that there is a (stand-alone) Prometheus server that must be downloaded/installed. This server then periodically makes HTTP GET requests (pull) to a list of application servers - such as a Java SpringBoot server to fetch (in-memory) stored metrics.

Ref: https://prometheus.io/docs/introduction/faq/#why-do-you-pull-rather-than-push?

Thus the (Spring Boot) application must expose a metrics end-point that the Prometheus server can pull from (default is /metrics).

Ref: https://github.com/prometheus/client_java

Thus there is much documentation available on Google but that is the (arguably convoluted) topology - along with arguments from the SoundCloud and Prometheus folks as to why a "pull" model is preferred over "push" as every other metrics framework employs.

like image 150
Darrell Teague Avatar answered Oct 11 '22 02:10

Darrell Teague