Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prometheus Endpoint Not Working Spring Boot 2.0.0.RC1 Spring Webflux enabled

I followed the documentation here (https://docs.spring.io/spring-boot/docs/2.0.0.RC1/reference/htmlsingle/#production-ready-endpoints-enabling-endpoints) and made sure application.yml file has the below

management:
  metrics:
    export:
      prometheus:
        enabled: true
  endpoints:
    web:
      expose:
        health, info, httptrace, metrics, threaddump, mappings, prometheus

As per the documentation (https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/actuator-api/html/#prometheus) the following doesn't work.

curl 'http://localhost:8080/actuator/prometheus' -i

I get 404 Handler mapping not found exception. Can someone please let me know how to enable prometheus endpoint for scraping purposes and what URL endpoint I need to use to test it out?

o.s.w.r.r.m.a.RequestMappingHandlerMapping[276] - Did not find handler method for [/actuator/prometheus]

All other endpoints health, info, httptrace, threaddump, mappings are working perfectly fine.

like image 250
ROCKY Avatar asked Feb 03 '18 23:02

ROCKY


5 Answers

A bit late - but just for the record - I can verify that this works now in 2.0.0.RELEASE.

Dependencies (gradle):

compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('io.micrometer:micrometer-registry-prometheus')

application.yaml (reference)

management:
  endpoints:
    web:
      exposure:
        include: health,info,prometheus

I also tested with RC1 - the prometheus endpoint does not show up for some reason - just as @ROCKY explained.

like image 160
Lachezar Balev Avatar answered Oct 27 '22 19:10

Lachezar Balev


There's some things you could check:

  1. Have you added the necessary MeterRegistry implementation so that the Prometheus "subsystem" of the Micrometer instrumentation library is present? (The Micrometer library is powering the Actuator implementation as of Spring Boot 2.0)

    <dependency>
        <groupId>io.micrometer</groupId>
        <artifactId>micrometer-registry-prometheus</artifactId>
    </dependency>
    

    Without a specific MeterRegistry implementation you just end up with the regular /actuator/metrics endpoint powered by the SimpleMeterRegistry implementation.

  2. Have you actually placed the mentioned properties in a application.[yml,yaml] file instead of application.properties? (I just stumbled upon the same with a fresh demo project generated with Spring Initializr.)

like image 42
mweirauch Avatar answered Oct 27 '22 18:10

mweirauch


spring boot does not expose prometheus endpoint by default even if you have >micrometer-registry-prometheus in you classpath.

<dependency>
            <groupId>io.micrometer</groupId>
            <artifactId>micrometer-registry-prometheus</artifactId>
    </dependency>  

you need to explicit tell spring boot to expose prometheus endpoint by below property.

management.endpoints.web.exposure.include=health,info,metrics,prometheus

like image 31
Niraj Sonawane Avatar answered Oct 27 '22 19:10

Niraj Sonawane


I experienced the same problem and managed to fix it by adding "include" tag into the configuration:

management:
  metrics:
    export:
      prometheus:
        enabled: true
  endpoints:
    web:
      exposure:
        include: prometheus,info,metrics,threaddump
like image 45
ypgrument Avatar answered Oct 27 '22 19:10

ypgrument


Had the same problem when I upgraded my application from 1.5 to 2.1.3. Was able to fix it by following this Spring Boot 2.0 Prometheus Backward Compatibility

You need micrometer-registry-prometheus in your dependency list and add below to your SpringBootApplication class

@Bean
public CollectorRegistry collectorRegistry() {
    return CollectorRegistry.defaultRegistry;
}
like image 22
dushshantha Avatar answered Oct 27 '22 19:10

dushshantha