Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot 2.2.2 - Prometheus not working in Actuator

I've upgraded my Spring Boot application to the latest 2.2.2 Boot version. Since then, I only have a metrics endpoint but no Prometheus.

My build.gradle.kts file has org.springframework.boot:spring-boot-starter-actuator as dependency, I also added io.micrometer:micrometer-registry-prometheus as the reference suggests (Prometheus endpoint).

My application.yml looks like the following:

management:
  server:
    port: 9000
  endpoints:
    web:
      exposure:
        include: health, shutdown, prometheus
  endpoint:
    shutdown:
      enabled: true

Can someone guide me to the right direction?

Edit: It was working in Spring Boot 2.2.0. This is the link to download an identical project: link

Edit 2: I can verify that it works with 2.2.1 as well.

like image 466
OCPi Avatar asked Dec 18 '19 12:12

OCPi


People also ask

How do I enable actuators in spring boot?

To enable Spring Boot actuator endpoints to your Spring Boot application, we need to add the Spring Boot Starter actuator dependency in our build configuration file. Maven users can add the below dependency in your pom. xml file. Gradle users can add the below dependency in your build.

How do I use spring boots with Prometheus?

Adding Prometheus to Spring Boot The first dependency we need to add is the Spring Boot Actuator. This is the part of Spring Boot which exposes some APIs, for health-checking and monitoring of your apps, as per the documentation: Actuator endpoints let you monitor and interact with your application.

Is spring boot actuator enabled by default?

In order to access the actuator endpoints using HTTP, we need to both enable and expose them. By default, all endpoints but /shutdown are enabled.


1 Answers

I followed your setup, I created a project from this project loaded Spring Boot 2.2.2.RELEASE, I added the following dependency for Prometheus

implementation("io.micrometer:micrometer-registry-prometheus")

Also I added the following configuration in application.yml

management:
  server:
    port: 9000
  endpoints:
    web:
      exposure:
        include: health, shutdown, prometheus
  endpoint:
    shutdown:
      enabled: true

When the application starts you will see the following info which shows you that 3 endpoints are exposed (health, shutdown and prometheus).

2020-01-05 23:48:19.489  INFO 7700 --- [           main] o.s.b.a.e.web.EndpointLinksResolver      : Exposing 3 endpoint(s) beneath base path '/actuator'

And used Postman for method GET this endpoint http://localhost:9000/actuator/prometheus and it works well. I created a repository by following these steps here So please let me know what error is displayed, or what happens when you don't get the expected result so that I can help and edit this answer.

like image 61
Jonathan JOhx Avatar answered Oct 13 '22 14:10

Jonathan JOhx