3

According to the documentation of the spring boot actuator

Auto-configuration enables the instrumentation of requests handled by Spring MVC. When management.metrics.web.server.auto-time-requests is true, this instrumentation occurs for all requests. Alternatively, when set to false, you can enable instrumentation by adding @Timed

And
By default, metrics are generated with the name, http.server.requests

When I access the /metrics endpoint I am getting

{
  "mem": 405105,
  "mem.free": 150352,
  "processors": 8,
  "instance.uptime": 440055,
  "uptime": 455888,
  "systemload.average": 1.904296875,
  "heap.committed": 315392,
  "heap.init": 262144,
  "heap.used": 164015,
  "heap": 4194304,
  "nonheap.committed": 92800,
  "nonheap.init": 4992,
  "nonheap.used": 89714,
  "nonheap": 0,
  "threads.peak": 64,
  "threads.daemon": 43,
  "threads.totalStarted": 95,
  "threads": 46,
  "classes": 12459,
  "classes.loaded": 12459,
  "classes.unloaded": 0,
  "gc.g1_young_generation.count": 12,
  "gc.g1_young_generation.time": 127,
  "gc.g1_old_generation.count": 0,
  "gc.g1_old_generation.time": 0,
  "httpsessions.max": -1,
  "httpsessions.active": 0,
  "datasource.primary.active": 0,
  "datasource.primary.usage": 0.0,
  "gauge.response.example.users": 2.0,
  "counter.status.200.example.users": 5
}

So the http.server.requests is not there. The counter.status.200.example kind of shows the requests that go through my application but they are separated per endpoint. I need an overall for the whole application. I've tried disabling the management.metrics.web.server.auto-time-requests and adding @Timed to the endpoints, but that did not work as well. The result was the same as the one above.

Does anyone know how I can show the overall requests that are made to the application? Thank you in advance.

*EDIT

when I add compile('io.micrometer:micrometer-registry-prometheus:latest.release') I get the following error

Parameter 0 of method prometheusEndpointFix in PrometheusEndpointConfiguration required a bean of type 'PrometheusEndpoint' that could not be found.

Even though the @Bean is there..

@Configuration
class PrometheusEndpointConfiguration {

  @Bean
  public PrometheusEndpoint prometheusEndpoint() {
    return new PrometheusEndpoint(CollectorRegistry.defaultRegistry);
  }
...
}
PPetkov
  • 240
  • 3
  • 13
  • This very much looks like the old Spring Boot 1.x actuator metrics. So I assume you are on Spring Boot 1.x, right? – mweirauch Jan 28 '19 at 22:16
  • yes, I am using Spring Boot 1.5.2 – PPetkov Jan 29 '19 at 08:57
  • I've also tried with `compile 'io.micrometer:micrometer-spring-legacy:latest.release'` which supports 1.5 and states the same for the http.server.requests metric https://micrometer.io/docs/ref/spring/1.5 – PPetkov Jan 29 '19 at 10:31

2 Answers2

3

One catch with it is when using the actuators and following the guide of spring boot 2.2.6 I noticed the http.server.requests will not be shown in the metrics list, if no requests have happen so far. After making the first REST request, the http metric becomes available.

Adam
  • 2,800
  • 1
  • 13
  • 15
2

When using Micrometer with Spring Boot 1.5 via micrometer-spring-legacy the "old" /metrics endpoint from the Spring Boot 1.5 Actuator framework will not get replaced with the Micrometer one. In a Spring Boot 1.5 application, the old actuator metrics implementation and Micrometer live totally independant next to each other.

Currently, the only way I know off for easily visualizing the Micrometer collected metrics in this scenario is using Micrometers Prometheus backend by including micrometer-registry-prometheus additionally to micrometer-spring-legacy. This will - by default - expose the /prometheus endpoint and expose the metrics in the Prometheus exposition format.

Of course, you could also roll your own endpoint implementation which mimics the Spring Boot 2 /actuator/metrics endpoint which queries the MeterRegistry and visualizes all contained metrics. But even then, this should be merely used for debugging things instead of permanently reading this endpoint and persisting that data somewhere in a metrics store. The Prometheus exposition format has been "developed" for that exact usecase. (And it's quite readable, so can serve as a first look entrypoint in case you are not scraping these metrics.)

mweirauch
  • 1,958
  • 11
  • 17
  • I edited my question adding the suggestion you made. – PPetkov Jan 30 '19 at 11:07
  • 1
    @PPetkov You must not use/add any extra Prometheus-Java specific libraries like `simpleclient_spring_boot`. Everything required is provided with the two Micrometer dependencies I mentioned. – mweirauch Jan 30 '19 at 11:57
  • I indeed had the `simpleclient_spring_boot` library in my project. Removing it fixed the issue. Thanks! – PPetkov Jan 30 '19 at 12:17
  • What are the two endpoints in this case? I know '/metrics' is one from Spring Actuator, which endpoint should I go for micrometer metrics? – San Aug 07 '20 at 19:32
  • @San as I had written in the answer, with Spring Boo 1.5 the only actuator endpoint which can be provided by Micrometer is adding `micrometer-registry-prometheus` which will expose the `/prometheus` endpoint. All other Micrometer backend implementations don't offer such a method because they operate push-based and thus don't need to be scraped at the application level, but are rather pushed by the application to the respective metrics store. – mweirauch Aug 09 '20 at 12:26
  • Does it really shows the api response times for each request? – Metalhead Dec 02 '20 at 13:31