I am trying to add custom metrics in my spring-boot application. I have looked at numerous examples and still, I'm failing to add a custom Counter.
application.properties
management.endpoint.metrics.enabled=true
management.endpoints.web.exposure.include=*
management.endpoint.prometheus.enabled=true
management.metrics.export.prometheus.enabled=true
code
static final Counter requests =
Counter.build().namespace("java").name("requests_total").help("Total requests.")
.register();
@CrossOrigin
@GetMapping("/test")
public int processRequest() {
requests.inc();
return (int) requests.get();
}
I can see the counter value increasing when I access the API. The problem is that I cannot find my newly created metrics on http://localhost:8080/actuator/prometheus and on the prometheus :9090 page. So I figure the counter is not getting registered(??). What am I missing here?