问题
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.
回答1:
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.
回答2:
There's some things you could check:
Have you added the necessary
MeterRegistryimplementation so that the Prometheus "subsystem" of theMicrometerinstrumentation 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
MeterRegistryimplementation you just end up with the regular/actuator/metricsendpoint powered by theSimpleMeterRegistryimplementation.Have you actually placed the mentioned properties in a
application.[yml,yaml]file instead ofapplication.properties? (I just stumbled upon the same with a fresh demo project generated with Spring Initializr.)
回答3:
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
回答4:
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;
}
来源:https://stackoverflow.com/questions/48603285/prometheus-endpoint-not-working-spring-boot-2-0-0-rc1-spring-webflux-enabled