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.
On Tuesday, 19 November 2024 at 14:04:36 UTC+5:30 Abhinav Singh wrote:

> 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;
> }
> }
>
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/prometheus-users/499f8f5d-ff52-43cc-a72b-965173138bdbn%40googlegroups.com.

Reply via email to