Class MicrometerMetricsRecorder
- All Implemented Interfaces:
MetricsRecorder
MetricsRecorder bridge that records every @RestOp call as a Micrometer
Timer sample on the configured MeterRegistry.
Metric shape
Each call records to one Timer named (by default) "http.server.requests" with four tags:
method— uppercased HTTP method (e.g.GET,POST).uri— the@RestOppath template (e.g./users/{id}), not the raw concrete URI. Using the template keeps tag cardinality bounded; raw URIs (/users/123,/users/124, ...) would explode the registry's series count. Empty string when the operation has no path pattern.status— HTTP response status code as a string (e.g.200,404,500).exception— the thrown exception's simple-name (e.g.BadRequest,NullPointerException), or "None" when the call completed normally.
The shape mirrors Spring Boot's
WebMvcMetricsFilter
convention so existing dashboards / alerts that scrape http.server.requests from Spring
Boot services keep working when those services are reimplemented on Juneau.
Wiring
The MetricsRecorder bean is picked up by juneau-rest-server through the
RestContext's bean store and invoked once per @RestOp call.
Customizing the metric name
Pass a non-default name to the two-arg constructor when the default "http.server.requests" doesn't match an existing dashboard / Prometheus rule set:
Per-operation overrides are available via RestOp.metricName().
When a non-empty metricName is passed to record(...), it takes precedence over the
recorder-level timer name. Per-op tags added via RestOp.metricTags()
are merged into the standard tag set as additional key=value pairs.
See Also:
- Since:
- 10.0.0
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionMicrometerMetricsRecorder(io.micrometer.core.instrument.MeterRegistry registry) Constructor using the default timer name "http.server.requests".MicrometerMetricsRecorder(io.micrometer.core.instrument.MeterRegistry registry, String timerName) Constructor with a custom timer name. -
Method Summary
Modifier and TypeMethodDescriptionio.micrometer.core.instrument.MeterRegistryReturns theMeterRegistrythis recorder publishes to.Returns the configured timer name.voidrecord(String opName, String httpMethod, String uriTemplate, int statusCode, Duration elapsed, Throwable error, String metricName, String metricTags) Records one per-request metric event.voidRecords one custom (non-request) observation event.
-
Field Details
-
DEFAULT_TIMER_NAME
Default timer name"http.server.requests"— matches Spring Boot's convention.- See Also:
-
NO_EXCEPTION_TAG
Tag value used for theexceptiontag when the call completed normally.- See Also:
-
-
Constructor Details
-
MicrometerMetricsRecorder
Constructor using the default timer name "http.server.requests".- Parameters:
registry- The MicrometerMeterRegistryto publish timers to. Must not benull .
-
MicrometerMetricsRecorder
public MicrometerMetricsRecorder(io.micrometer.core.instrument.MeterRegistry registry, String timerName) Constructor with a custom timer name.- Parameters:
registry- The MicrometerMeterRegistryto publish timers to. Must not benull .timerName- The timer name. Must not benull or blank.
-
-
Method Details
-
getRegistry
Returns theMeterRegistrythis recorder publishes to.- Returns:
- The
MeterRegistry.
-
getTimerName
Returns the configured timer name.- Returns:
- The timer name.
-
record
public void record(String opName, String httpMethod, String uriTemplate, int statusCode, Duration elapsed, Throwable error, String metricName, String metricTags) Description copied from interface:MetricsRecorderRecords one per-request metric event.- Specified by:
recordin interfaceMetricsRecorder- Parameters:
opName- The fully-qualified@RestOpmethod name (e.g."com.example.OrderResource.create(java.lang.String,com.example.Order)"). Nevernull ; never blank.httpMethod- The uppercased HTTP method of the request (e.g."GET","POST"). Nevernull ; never blank.uriTemplate- The@RestOppath template (e.g."/users/{id}"), not the raw concrete URI. Bridges should use this as theuritag to keep cardinality bounded. May be empty for resource-level operations that match/*; nevernull .statusCode- The HTTP response status code (e.g.200,404,500). If the handler threw before the status was set, this is the framework's inferred status (typically500for an unmapped exception, or the exception's status for aBasicHttpException).elapsed- Wall-clock duration of the@RestOpinvocation. Nevernull ; never negative.error- The exception thrown by the handler, ornull if the call completed normally. Bridges typically derive anexceptiontag from the throwable's simple class name, or"None"when null (mirrors Spring Boot'sWebMvcMetricsFilterconvention).metricName- Per-op metric name override fromRestOp.metricName(). Empty string (default) means the implementation should use its own default name derivation. Nevernull .metricTags- Per-op additional metric tags fromRestOp.metricTags(). Format: comma-separatedkey=valuepairs (e.g."team=payments,region=us-east"). Empty string (default) means no additional tags. Nevernull .
-
record
Description copied from interface:MetricsRecorderRecords one custom (non-request) observation event.Unlike
MetricsRecorder.record(String, String, String, int, Duration, Throwable, String, String), this entry point is not tied to an HTTP request — it is the substrate for the explicit programmatic observation API (Observations) so application code can time an arbitrary block of work. Bridge implementations record a timer namedmetricNamecarryingmetricTags(plus anexceptiontag derived fromerror).The default implementation does nothing — a bridge that does not override it simply does not record custom observations, and the no-backend path stays zero-allocation. The shipped Micrometer bridge overrides it.
- Specified by:
recordin interfaceMetricsRecorder- Parameters:
metricName- The timer name (e.g."order.load"). Nevernull ; never blank.metricTags- Additional tags as comma-separatedkey=valuepairs (e.g."team=payments,region=us-east"). Empty string means no additional tags. Nevernull .elapsed- Wall-clock duration of the observed block. Nevernull ; never negative.error- The exception thrown by the observed block, ornull if it completed normally.
-