/actuator/prometheus is empty while /actuator/metrics shows the data

204 views
Skip to first unread message

Abhinav Singh

unread,
Nov 19, 2024, 3:34:36 AM11/19/24
to Prometheus Users
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;
}
}




Abhinav Singh

unread,
Nov 19, 2024, 12:14:03 PM11/19/24
to Prometheus Users
Ok, I fixed this issue by simply removing PrometheusMeterRegistry bean from config:


@Bean
@Primary
public PrometheusMeterRegistry meterRegistry() {
return new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
}

By removing the manual PrometheusMeterRegistry bean definition, Spring Boot's auto-configuration handles the creation and wiring, which ensures /actuator/prometheus works as expected.
Reply all
Reply to author
Forward
0 new messages