Hi team,
I am facing this strange issue. When I curl /actuator/metrics I see all the metrics shows up there but when I try to access /actuator/prometheus then it return empty.
I tried to fetch the registry value using
System.out.println(prometheusMeterRegistry.scrape());
and I can see the data is present in the registry. What I am doing wrong?
Here is my configs:
logging.config=classpath:logback-test.xml
spring.mvc.servlet.path=/
server.servlet.context-path=/
# Actuator endpoints
management.endpoints.web.exposure.include=*
management.endpoint.metrics.enabled=true
management.endpoint.prometheus.enabled=true
management.endpoint.health.show-details=always
management.metrics.enable.spring.batch=true
# Metrics configuration
management.metrics.enable.all=true
management.metrics.distribution.percentiles-histogram.http.server.requests=true
management.metrics.tags.application=${spring.application.name:batch-app}
# Batch metrics specific
spring.batch.metrics.enable=true
spring.batch.metrics.job.enabled=true
spring.batch.metrics.step.enabled=true
# Optional: Configure base path for actuator endpoints
management.endpoints.web.base-path=/actuator
# Optional: Configure specific port for actuator endpoints
management.server.port=8088
# Optional: Configure logging for metrics (helpful for debugging)
logging.level.io.micrometer=DEBUG
logging.level.org.springframework.batch=DEBUG
management.health.elasticsearch.enabled=false
@Slf4j
@Configuration
public class MetricConfig {
@Bean
@Primary
public PrometheusMeterRegistry meterRegistry() {
return new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
}
@Bean
@Primary
public ObservationRegistry observationRegistry(PrometheusMeterRegistry prometheusMeterRegistry) {
ObservationRegistry observationRegistry = ObservationRegistry.create();
observationRegistry.observationConfig().observationHandler(
new DefaultMeterObservationHandler(prometheusMeterRegistry));
return observationRegistry;
}
}