Class MetricCollectingClientInterceptor
java.lang.Object
io.micrometer.core.instrument.binder.grpc.AbstractMetricCollectingInterceptor
io.micrometer.core.instrument.binder.grpc.MetricCollectingClientInterceptor
- All Implemented Interfaces:
io.grpc.ClientInterceptor
public class MetricCollectingClientInterceptor extends AbstractMetricCollectingInterceptor implements io.grpc.ClientInterceptor
A gRPC client interceptor that will collect metrics using the given
MeterRegistry.
Usage:
ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 8080)
.intercept(new MetricCollectingClientInterceptor(meterRegistry))
.build();
channel.newCall(method, options);
- Since:
- 1.7.0
-
Nested Class Summary
Nested classes/interfaces inherited from class io.micrometer.core.instrument.binder.grpc.AbstractMetricCollectingInterceptor
AbstractMetricCollectingInterceptor.MetricSet -
Field Summary
Fields inherited from class io.micrometer.core.instrument.binder.grpc.AbstractMetricCollectingInterceptor
counterCustomizer, eagerInitializedCodes, registry, timerCustomizer -
Constructor Summary
Constructors Constructor Description MetricCollectingClientInterceptor(MeterRegistry registry)Creates a new gRPC client interceptor that will collect metrics into the givenMeterRegistry.MetricCollectingClientInterceptor(MeterRegistry registry, java.util.function.UnaryOperator<Counter.Builder> counterCustomizer, java.util.function.UnaryOperator<Timer.Builder> timerCustomizer, io.grpc.Status.Code... eagerInitializedCodes)Creates a new gRPC client interceptor that will collect metrics into the givenMeterRegistryand uses the given customizers to configure theCounters andTimers. -
Method Summary
Modifier and Type Method Description <Q, A> io.grpc.ClientCall<Q,A>interceptCall(io.grpc.MethodDescriptor<Q,A> methodDescriptor, io.grpc.CallOptions callOptions, io.grpc.Channel channel)protected CounternewRequestCounterFor(io.grpc.MethodDescriptor<?,?> method)Creates a new request counter for the given method.protected CounternewResponseCounterFor(io.grpc.MethodDescriptor<?,?> method)Creates a new response counter for the given method.protected java.util.function.Function<io.grpc.Status.Code,Timer>newTimerFunction(io.grpc.MethodDescriptor<?,?> method)Creates a new function that returns a timer for a given code for the given method.Methods inherited from class io.micrometer.core.instrument.binder.grpc.AbstractMetricCollectingInterceptor
asTimerFunction, metricsFor, newMetricsFor, prepareCounterFor, prepareTimerFor, preregisterMethod, preregisterServiceMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
MetricCollectingClientInterceptor
Creates a new gRPC client interceptor that will collect metrics into the givenMeterRegistry.- Parameters:
registry- The registry to use.
-
MetricCollectingClientInterceptor
public MetricCollectingClientInterceptor(MeterRegistry registry, java.util.function.UnaryOperator<Counter.Builder> counterCustomizer, java.util.function.UnaryOperator<Timer.Builder> timerCustomizer, io.grpc.Status.Code... eagerInitializedCodes)Creates a new gRPC client interceptor that will collect metrics into the givenMeterRegistryand uses the given customizers to configure theCounters andTimers.- Parameters:
registry- The registry to use.counterCustomizer- The unary function that can be used to customize the created counters.timerCustomizer- The unary function that can be used to customize the created timers.eagerInitializedCodes- The status codes that should be eager initialized.
-
-
Method Details
-
newRequestCounterFor
Description copied from class:AbstractMetricCollectingInterceptorCreates a new request counter for the given method.- Specified by:
newRequestCounterForin classAbstractMetricCollectingInterceptor- Parameters:
method- The method to create the counter for.- Returns:
- The newly created request counter.
-
newResponseCounterFor
Description copied from class:AbstractMetricCollectingInterceptorCreates a new response counter for the given method.- Specified by:
newResponseCounterForin classAbstractMetricCollectingInterceptor- Parameters:
method- The method to create the counter for.- Returns:
- The newly created response counter.
-
newTimerFunction
protected java.util.function.Function<io.grpc.Status.Code,Timer> newTimerFunction(io.grpc.MethodDescriptor<?,?> method)Description copied from class:AbstractMetricCollectingInterceptorCreates a new function that returns a timer for a given code for the given method.- Specified by:
newTimerFunctionin classAbstractMetricCollectingInterceptor- Parameters:
method- The method to create the timer for.- Returns:
- The newly created function that returns a timer for a given code.
-
interceptCall
public <Q, A> io.grpc.ClientCall<Q,A> interceptCall(io.grpc.MethodDescriptor<Q,A> methodDescriptor, io.grpc.CallOptions callOptions, io.grpc.Channel channel)- Specified by:
interceptCallin interfaceio.grpc.ClientInterceptor
-