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
How can I see the metric requests_total in my https://localhost:8003/prometheus endpoint
static final Counter requests = Counter.build()
.name("requests_total").help("Total requests.").register();
someMethod(){
requests.inc();
}
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>