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
  • Constructor Details

    • MetricCollectingClientInterceptor

      public MetricCollectingClientInterceptor(MeterRegistry registry)
      Creates a new gRPC client interceptor that will collect metrics into the given MeterRegistry.
      Parameters:
      registry - The registry to use.
    • MetricCollectingClientInterceptor

      public MetricCollectingClientInterceptor(MeterRegistry registry, UnaryOperator<Counter.Builder> counterCustomizer, UnaryOperator<Timer.Builder> timerCustomizer, io.grpc.Status.Code... eagerInitializedCodes)
      Creates a new gRPC client interceptor that will collect metrics into the given MeterRegistry and uses the given customizers to configure the Counters and Timers.
      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

      protected Counter newRequestCounterFor(io.grpc.MethodDescriptor<?,?> method)
      Description copied from class: AbstractMetricCollectingInterceptor
      Creates a new request counter for the given method.
      Specified by:
      newRequestCounterFor in class AbstractMetricCollectingInterceptor
      Parameters:
      method - The method to create the counter for.
      Returns:
      The newly created request counter.
    • newResponseCounterFor

      protected Counter newResponseCounterFor(io.grpc.MethodDescriptor<?,?> method)
      Description copied from class: AbstractMetricCollectingInterceptor
      Creates a new response counter for the given method.
      Specified by:
      newResponseCounterFor in class AbstractMetricCollectingInterceptor
      Parameters:
      method - The method to create the counter for.
      Returns:
      The newly created response counter.
    • newTimerFunction

      protected Function<io.grpc.Status.Code,Timer> newTimerFunction(io.grpc.MethodDescriptor<?,?> method)
      Description copied from class: AbstractMetricCollectingInterceptor
      Creates a new function that returns a timer for a given code for the given method.
      Specified by:
      newTimerFunction in class AbstractMetricCollectingInterceptor
      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:
      interceptCall in interface io.grpc.ClientInterceptor