Skip to content

Commit 1893f93

Browse files
committed
Rework 'Supported Metrics' reference documentation
Rework the 'Supported Metrics' documentation to improve consistency access subsections. Details about the `@Timer` annotation have been pulled into a new section so that they can be referenced rather than repeated. See gh-22217
1 parent 9f16491 commit 1893f93

File tree

1 file changed

+131
-66
lines changed

1 file changed

+131
-66
lines changed

spring-boot-project/spring-boot-docs/src/docs/asciidoc/production-ready-features.adoc

+131-66
Original file line numberDiff line numberDiff line change
@@ -2122,55 +2122,56 @@ You can also change the interval at which metrics are sent to Wavefront:
21222122

21232123

21242124
[[production-ready-metrics-meter]]
2125-
=== Supported Metrics
2126-
Spring Boot registers the following core metrics when applicable:
2127-
2128-
* JVM metrics, report utilization of:
2129-
** Various memory and buffer pools
2130-
** Statistics related to garbage collection
2131-
** Threads utilization
2132-
** Number of classes loaded/unloaded
2125+
=== Supported Metrics and Meters
2126+
Spring Boot provides automatic meter registration for a wide variety of technologies.
2127+
In most situations, the out-of-the-box defaults will provide sensible metrics that can be published to any of the supported monioring systems.
2128+
2129+
2130+
2131+
[[production-ready-metrics-jvm]]
2132+
==== JVM Metrics
2133+
Auto-configuration will enable JVM Metrics using core Micrometer classes.
2134+
JVM metrics are published under the `jvm.` meter name.
2135+
2136+
The following JVM metrics are provided:
2137+
2138+
* Various memory and buffer pool details
2139+
* Statistics related to garbage collection
2140+
* Threads utilization
2141+
* The Number of classes loaded/unloaded
2142+
2143+
2144+
2145+
[[production-ready-metrics-system]]
2146+
==== System Metrics
2147+
Auto-configuration will enable system metrics using core Micrometer classes.
2148+
System are published under the `system.` and `process.` meter names.
2149+
2150+
The following system metrics are provided:
2151+
21332152
* CPU metrics
21342153
* File descriptor metrics
2135-
* Kafka consumer, producer, and streams metrics
2136-
* Log4j2 metrics: record the number of events logged to Log4j2 at each level
2137-
* Logback metrics: record the number of events logged to Logback at each level
2138-
* MongoDB metrics for all commands issued from the client and for client connection pool information
2139-
* Uptime metrics: report a gauge for uptime and a fixed gauge representing the application's absolute start time
2140-
* Tomcat metrics (`server.tomcat.mbeanregistry.enabled` must be set to `true` for all Tomcat metrics to be registered)
2141-
* {spring-integration-docs}system-management.html#micrometer-integration[Spring Integration] metrics
2154+
* Uptime metrics (both the amount of time the application has been running as well as a fixed gauge of the absolute start time)
21422155

21432156

21442157

2145-
[[production-ready-metrics-spring-mvc]]
2146-
==== Spring MVC Metrics
2147-
Auto-configuration enables the instrumentation of requests handled by Spring MVC.
2148-
When `management.metrics.web.server.request.autotime.enabled` is `true`, this instrumentation occurs for all requests.
2149-
Alternatively, when set to `false`, you can enable instrumentation by adding `@Timed` to a request-handling method:
2158+
[[production-ready-metrics-logger]]
2159+
==== Logger Metrics
2160+
Auto-configuration enables the event metrics for both Logback and Log4J2.
2161+
Details are published under the `log4j2.events.` or `logback.events.` meter names.
21502162

2151-
[source,java,pending-extract=true,indent=0]
2152-
----
2153-
@RestController
2154-
@Timed <1>
2155-
public class MyController {
21562163

2157-
@GetMapping("/api/people")
2158-
@Timed(extraTags = { "region", "us-east-1" }) <2>
2159-
@Timed(value = "all.people", longTask = true) <3>
2160-
public List<Person> listPeople() { ... }
2161-
2162-
}
2163-
----
2164-
<1> A controller class to enable timings on every request handler in the controller not directly annotated with `@Timed`.
2165-
<2> A method to enable for an individual endpoint.
2166-
This is not necessary if you have it on the class, but can be used to customize the timer for this particular endpoint.
2167-
<3> A method with `longTask = true` to enable a long task timer for the method.
2168-
Long task timers require a separate metric name, and can be stacked with a short task timer.
21692164

2165+
[[production-ready-metrics-spring-mvc]]
2166+
==== Spring MVC Metrics
2167+
Auto-configuration enables the instrumentation of all requests handled by Spring MVC controllers and functional handlers.
21702168
By default, metrics are generated with the name, `http.server.requests`.
21712169
The name can be customized by setting the configprop:management.metrics.web.server.request.metric-name[] property.
21722170

2173-
By default, Spring MVC-related metrics are tagged with the following information:
2171+
`@Timed` annotations are supported on `@Controller` classes and `@RequestMapping` methods (see <<production-ready-metrics-timed-annotation>> for details).
2172+
If you don't want to record metrics for all Spring MVC requests, you can set configprop:management.metrics.web.server.request.autotime.enabled[] to `false` and exclusively use `@Timed` annotations instead.
2173+
2174+
By default, Spring MVC related metrics are tagged with the following information:
21742175

21752176
|===
21762177
| Tag | Description
@@ -2202,14 +2203,14 @@ Applications can opt-in and record exceptions by <<spring-boot-features.adoc#boo
22022203

22032204
[[production-ready-metrics-web-flux]]
22042205
==== Spring WebFlux Metrics
2205-
Auto-configuration enables the instrumentation of all requests handled by WebFlux controllers and functional handlers.
2206-
When `management.metrics.web.server.request.autotime.enabled` is `true`, this instrumentation occurs for all requests.
2207-
Alternatively, when set to `false`, you can enable instrumentation by adding `@Timed` to a request-handling method in the same way the Spring MVC example above.
2206+
Auto-configuration enables the instrumentation of all requests handled by Spring WebFlux controllers and functional handlers.
2207+
By default, metrics are generated with the name, `http.server.requests`.
2208+
The name can be customized by setting the configprop:management.metrics.web.server.request.metric-name[] property.
22082209

2209-
By default, metrics are generated with the name `http.server.requests`.
2210-
You can customize the name by setting the configprop:management.metrics.web.server.request.metric-name[] property.
2210+
`@Timed` annotations are supported on `@Controller` classes and `@RequestMapping` methods (see <<production-ready-metrics-timed-annotation>> for details).
2211+
If you don't want to record metrics for all Spring WebFlux requests, you can set configprop:management.metrics.web.server.request.autotime.enabled[] to `false` and exclusively use `@Timed` annotations instead.
22112212

2212-
By default, WebFlux-related metrics are tagged with the following information:
2213+
By default, WebFlux related metrics are tagged with the following information:
22132214

22142215
|===
22152216
| Tag | Description
@@ -2241,31 +2242,13 @@ Applications can opt-in and record exceptions by <<spring-boot-features.adoc#boo
22412242

22422243
[[production-ready-metrics-jersey-server]]
22432244
==== Jersey Server Metrics
2244-
When Micrometer's `micrometer-jersey2` module is on the classpath, auto-configuration enables the instrumentation of requests handled by the Jersey JAX-RS implementation.
2245-
When `management.metrics.web.server.request.autotime.enabled` is `true`, this instrumentation occurs for all requests.
2246-
Alternatively, when set to `false`, you can enable instrumentation by adding `@Timed` to a request-handling method:
2247-
2248-
[source,java,pending-extract=true,indent=0]
2249-
----
2250-
@Component
2251-
@Path("/api/people")
2252-
@Timed <1>
2253-
public class Endpoint {
2254-
@GET
2255-
@Timed(extraTags = { "region", "us-east-1" }) <2>
2256-
@Timed(value = "all.people", longTask = true) <3>
2257-
public List<Person> listPeople() { ... }
2258-
}
2259-
----
2260-
<1> On a resource class to enable timings on every request handler in the resource.
2261-
<2> On a method to enable for an individual endpoint.
2262-
This is not necessary if you have it on the class, but can be used to further customize the timer for this particular endpoint.
2263-
<3> On a method with `longTask = true` to enable a long task timer for the method.
2264-
Long task timers require a separate metric name, and can be stacked with a short task timer.
2265-
2245+
Auto-configuration enables the instrumentation of all requests handled by the Jersey JAX-RS implementation whenever Micrometer's `micrometer-jersey2` module is on the classpath.
22662246
By default, metrics are generated with the name, `http.server.requests`.
22672247
The name can be customized by setting the configprop:management.metrics.web.server.request.metric-name[] property.
22682248

2249+
`@Timed` annotations are supported on request-handling classes and methods (see <<production-ready-metrics-timed-annotation>> for details).
2250+
If you don't want to record metrics for all Jersey requests, you can set configprop:management.metrics.web.server.request.autotime.enabled[] to `false` and exclusively use `@Timed` annotations instead.
2251+
22692252
By default, Jersey server metrics are tagged with the following information:
22702253

22712254
|===
@@ -2332,6 +2315,14 @@ There are convenience static functions in `RestTemplateExchangeTags` and `WebCli
23322315

23332316

23342317

2318+
==== Tomcat Metrics
2319+
Auto-configuration will enable the instrumentation of Tomcat only when an `MBeanRegistry` is enabled.
2320+
By default, the `MBeanRegistry` is disabled, but you can enable it by setting configprop:server.tomcat.mbeanregistry.enabled[] to `true`.
2321+
2322+
Tomcat metrics are published under the `tomcat.` meter name.
2323+
2324+
2325+
23352326
[[production-ready-metrics-cache]]
23362327
==== Cache Metrics
23372328
Auto-configuration enables the instrumentation of all available ``Cache``s on startup with metrics prefixed with `cache`.
@@ -2394,6 +2385,14 @@ Auto-configuration will enable the instrumentation of all available RabbitMQ con
23942385

23952386

23962387

2388+
2389+
[[production-ready-metrics-integration]]
2390+
==== Spring Integration Metrics
2391+
Spring Integration provides {spring-integration-docs}system-management.html#micrometer-integration[Micrometer support] automatically whenever a `MeterRegistry` bean is available.
2392+
Metrics are published under the `spring.integration.` meter name.
2393+
2394+
2395+
23972396
[[production-ready-metrics-kafka]]
23982397
==== Kafka Metrics
23992398
Auto-configuration will register a `MicrometerConsumerListener` and `MicrometerProducerListener` for the auto-configured consumer factory and producer factory respectively.
@@ -2447,6 +2446,9 @@ To disable the auto-configured command metrics, set the following property:
24472446
enabled: false
24482447
----
24492448

2449+
2450+
2451+
[[production-ready-metrics-mongodb-connectionpool]]
24502452
===== Connection Pool Metrics
24512453
Auto-configuration will register a `MongoMetricsConnectionPoolListener` with the auto-configured `MongoClient`.
24522454

@@ -2487,6 +2489,69 @@ To disable the auto-configured connection pool metrics, set the following proper
24872489

24882490

24892491

2492+
[[production-ready-metrics-timed-annotation]]
2493+
==== @Timed Annotation Support
2494+
The `@Timed` annotation from the `io.micrometer.core.annotation` package can be used with several of the supported technologies listed above.
2495+
If supported, the annotation can be used either at the class-level or the method-level.
2496+
2497+
For example, the following code shows how the annotation can be used to instrument all request mappings in a `@RestController`:
2498+
2499+
[source,java,pending-extract=true,indent=0]
2500+
----
2501+
@RestController
2502+
@Timed
2503+
public class MyController {
2504+
2505+
@GetMapping("/api/addresses")
2506+
public List<Person> listAddress() { ... }
2507+
2508+
@GetMapping("/api/people")
2509+
public List<Person> listPeople() { ... }
2510+
2511+
}
2512+
----
2513+
2514+
If you only want to instrument a single mapping, you can use the annotation on the method instead of the class:
2515+
2516+
[source,java,pending-extract=true,indent=0]
2517+
----
2518+
@RestController
2519+
public class MyController {
2520+
2521+
@GetMapping("/api/addresses")
2522+
public List<Person> listAddress() { ... }
2523+
2524+
@GetMapping("/api/people")
2525+
@Timed
2526+
public List<Person> listPeople() { ... }
2527+
2528+
}
2529+
----
2530+
2531+
You can also combine class-level and method-level annotations if you want to change timing details for a specific method:
2532+
2533+
[source,java,pending-extract=true,indent=0]
2534+
----
2535+
@RestController
2536+
@Timed
2537+
public class MyController {
2538+
2539+
@GetMapping("/api/addresses")
2540+
public List<Person> listPeople() { ... }
2541+
2542+
@GetMapping("/api/people")
2543+
@Timed(extraTags = { "region", "us-east-1" })
2544+
@Timed(value = "all.people", longTask = true)
2545+
public List<Person> listPeople() { ... }
2546+
2547+
}
2548+
----
2549+
2550+
NOTE: A `@Timed` annotation with `longTask = true` will enable a long task timer for the method.
2551+
Long task timers require a separate metric name, and can be stacked with a short task timer.
2552+
2553+
2554+
24902555
[[production-ready-metrics-custom]]
24912556
=== Registering Custom Metrics
24922557
To register custom metrics, inject `MeterRegistry` into your component, as shown in the following example:

0 commit comments

Comments
 (0)