public final class DropwizardMetricCollectingService<I extends Request,O extends Response> extends DecoratingService<I,O,I,O>
Service
to collect metrics into Dropwizard MetricRegistry
.
To use, simply prepare a MetricRegistry
and add this decorator to a service specification.
Example:
MetricRegistry metricRegistry = new MetricRegistry();
serverBuilder.serviceAt(
"/service",
ThriftService.of(handler).decorate(
DropwizardMetricCollectingService.newDecorator(metricRegistry, "services")));
It is generally recommended to define your own name for the service instead of using something like the Java class to make sure otherwise safe changes like renames don't break metrics.
Modifier and Type | Method and Description |
---|---|
static <I extends Request,O extends Response> |
newDecorator(com.codahale.metrics.MetricRegistry metricRegistry,
java.util.function.Function<? super RequestLog,java.lang.String> metricNameFunc)
Returns a new
Service decorator that tracks request stats using the Dropwizard metrics
library. |
static <I extends Request,O extends Response> |
newDecorator(com.codahale.metrics.MetricRegistry metricRegistry,
java.lang.String metricNamePrefix)
Returns a new
Service decorator that tracks request stats using the Dropwizard metrics
library. |
O |
serve(ServiceRequestContext ctx,
I req)
Serves an incoming
Request . |
as, delegate, serviceAdded, toString
public static <I extends Request,O extends Response> java.util.function.Function<Service<? super I,? extends O>,DropwizardMetricCollectingService<I,O>> newDecorator(com.codahale.metrics.MetricRegistry metricRegistry, java.util.function.Function<? super RequestLog,java.lang.String> metricNameFunc)
Service
decorator that tracks request stats using the Dropwizard metrics
library.metricRegistry
- the MetricRegistry
to store metrics into.metricNameFunc
- the function that transforms a RequestLog
into a metric namepublic static <I extends Request,O extends Response> java.util.function.Function<Service<? super I,? extends O>,DropwizardMetricCollectingService<I,O>> newDecorator(com.codahale.metrics.MetricRegistry metricRegistry, java.lang.String metricNamePrefix)
Service
decorator that tracks request stats using the Dropwizard metrics
library.metricRegistry
- the MetricRegistry
to store metrics into.metricNamePrefix
- the prefix of the names of the metrics created by the returned decorator.