0

I have a spring boot application where for certain legacy reasons I cannot use spring actuator.

I was able to expose a prometheus end point and see a lot of default metrics. But I am not able to see the metrics that I am myself adding.

The code below works.

@Configuration
public class PrometheusMonitoringConfig {

    @Bean
    public PrometheusMeterRegistry prometheusMeterRegistry() {
        PrometheusMeterRegistry prometheusMeterRegistry=new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
        Metrics.globalRegistry.add(prometheusMeterRegistry);
        return prometheusMeterRegistry;
    }

}

@Autowired
PrometheusMeterRegistry prometheusRegistry;


//This is the prometheus http end point
@Override
public Response getPrometheus(HttpHeaders headers, HttpServletRequest request) {
    Response response = Response.status(Response.Status.OK).entity(prometheusRegistry.scrape()).build();

    return response;
}

At this point when I hit this, I see a lot of data https://localhost:8003/prometheus

But if I add this, even though I can see the counter go up when I put a breakpoint in the code, I do not see it in the metrics end point

   static final Counter requests = Counter.build()   .name("requests_total").help("Total requests.").labelNames("someLabel").register();
    
    someMethod(){
     requests.labels("someLabel").inc();
    }

How can I see the metric requests_total in my https://localhost:8003/prometheus endpoint ?

These are the dependencies I added in my maven pom

<dependency>
    <groupId>io.micrometer</groupId>
    <artifactId>micrometer-registry-prometheus</artifactId>
    <version>1.11.2</version>
</dependency>
<!-- Hotspot JVM metrics-->
<dependency>
    <groupId>io.prometheus</groupId>
    <artifactId>simpleclient_hotspot</artifactId>
    <version>0.16.0</version>
</dependency>
developer747
  • 15,419
  • 26
  • 93
  • 147

0 Answers0