Spring Boot exposes a variety of metrics about the embedded Tomcat server when server.tomcat.mbeanregistry.enabled=true.
However, while some of these metrics may be interesting, many may be useless.
For this reason, the MicroExtensionCommon library implements a TomcatMetricsMeterFilter for Micrometer which filters which meters are actually registered and end up being scraped by registries used by Prometheus or OpenTelemetry.
The goal is to allow clients to whitelist specific Tomcat metrics they want to expose and keep the rest disabled to avoid wasting resources needlessly during scrape events.
Usage is straightforward:
Enable the standard Tomcat Metrics binding functionality by setting server.tomcat.mbeanregistry.enabled=true
|
Note
|
This may result in 2MB of additional heap memory being consumed, as indicated by Spring Boot maintainers. |
If MicroExtensionCommon is a dependency of the running application, and Micrometer and Tomcat are both available, the registered meters will automatically be filtered down to just a handful of lightweight items.
For more details, or to tune this behavior further, please see the Tomcat Metrics Meter Filter Properties documentation.
It will also be helpful to review the Javadocs of TomcatMetricsMeterFilter, TomcatMetricsMeterFilterProperties, and MicrometerTomcatMetricsAutoConfiguration.