Class AbstractMetricCollectingInterceptor
java.lang.Object
io.micrometer.core.instrument.binder.grpc.AbstractMetricCollectingInterceptor
- Direct Known Subclasses:
MetricCollectingClientInterceptor,MetricCollectingServerInterceptor
An abstract gRPC interceptor that will collect metrics.
- Since:
- 1.7.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classContainer for all metrics of a certain call. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected UnaryOperator<Counter.Builder>protected io.grpc.Status.Code[]protected MeterRegistryprotected UnaryOperator<Timer.Builder> -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractMetricCollectingInterceptor(MeterRegistry registry)Creates a new gRPC interceptor that will collect metrics into the givenMeterRegistry.protectedAbstractMetricCollectingInterceptor(MeterRegistry registry, UnaryOperator<Counter.Builder> counterCustomizer, UnaryOperator<Timer.Builder> timerCustomizer, io.grpc.Status.Code... eagerInitializedCodes)Creates a new gRPC interceptor that will collect metrics into the givenMeterRegistryand uses the given customizers to configure theCounters andTimers. -
Method Summary
Modifier and TypeMethodDescriptionasTimerFunction(Supplier<Timer.Builder> timerTemplate)Creates a new timer function using the given template.metricsFor(io.grpc.MethodDescriptor<?,?> method)Gets or creates aAbstractMetricCollectingInterceptor.MetricSetfor the given gRPC method.newMetricsFor(io.grpc.MethodDescriptor<?,?> method)Creates aAbstractMetricCollectingInterceptor.MetricSetfor the given gRPC method.protected abstract CounternewRequestCounterFor(io.grpc.MethodDescriptor<?,?> method)Creates a new request counter for the given method.protected abstract CounternewResponseCounterFor(io.grpc.MethodDescriptor<?,?> method)Creates a new response counter for the given method.newTimerFunction(io.grpc.MethodDescriptor<?,?> method)Creates a new function that returns a timer for a given code for the given method.protected static Counter.BuilderprepareCounterFor(io.grpc.MethodDescriptor<?,?> method, String name, String description)Creates a new counter builder for the given method.protected static Timer.BuilderprepareTimerFor(io.grpc.MethodDescriptor<?,?> method, String name, String description)Creates a new timer builder for the given method.voidpreregisterMethod(io.grpc.MethodDescriptor<?,?> method)Pre-registers the given method.voidpreregisterService(io.grpc.ServiceDescriptor service)Pre-registers the all methods provided by the given service.
-
Field Details
-
registry
-
counterCustomizer
-
timerCustomizer
-
eagerInitializedCodes
protected final io.grpc.Status.Code[] eagerInitializedCodes
-
-
Constructor Details
-
AbstractMetricCollectingInterceptor
Creates a new gRPC interceptor that will collect metrics into the givenMeterRegistry. This method won't use any customizers and will only initialize theOKstatus.- Parameters:
registry- The registry to use.
-
AbstractMetricCollectingInterceptor
protected AbstractMetricCollectingInterceptor(MeterRegistry registry, UnaryOperator<Counter.Builder> counterCustomizer, UnaryOperator<Timer.Builder> timerCustomizer, io.grpc.Status.Code... eagerInitializedCodes)Creates a new gRPC 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
-
prepareCounterFor
protected static Counter.Builder prepareCounterFor(io.grpc.MethodDescriptor<?,?> method, String name, String description)Creates a new counter builder for the given method. By default the base unit will be messages.- Parameters:
method- The method the counter will be created for.name- The name of the counter to use.description- The description of the counter to use.- Returns:
- The newly created counter builder.
-
prepareTimerFor
protected static Timer.Builder prepareTimerFor(io.grpc.MethodDescriptor<?,?> method, String name, String description)Creates a new timer builder for the given method.- Parameters:
method- The method the timer will be created for.name- The name of the timer to use.description- The description of the timer to use.- Returns:
- The newly created timer builder.
-
preregisterService
public void preregisterService(io.grpc.ServiceDescriptor service)Pre-registers the all methods provided by the given service. This will initialize all default counters and timers for those methods.- Parameters:
service- The service to initialize the meters for.- See Also:
preregisterMethod(MethodDescriptor)
-
preregisterMethod
public void preregisterMethod(io.grpc.MethodDescriptor<?,?> method)Pre-registers the given method. This will initialize all default counters and timers for that method.- Parameters:
method- The method to initialize the meters for.
-
metricsFor
protected final AbstractMetricCollectingInterceptor.MetricSet metricsFor(io.grpc.MethodDescriptor<?,?> method)Gets or creates aAbstractMetricCollectingInterceptor.MetricSetfor the given gRPC method. This will initialize all default counters and timers for that method.- Parameters:
method- The method to get the metric set for.- Returns:
- The metric set for the given method.
- See Also:
newMetricsFor(MethodDescriptor)
-
newMetricsFor
protected AbstractMetricCollectingInterceptor.MetricSet newMetricsFor(io.grpc.MethodDescriptor<?,?> method)Creates aAbstractMetricCollectingInterceptor.MetricSetfor the given gRPC method. This will initialize all default counters and timers for that method.- Parameters:
method- The method to get the metric set for.- Returns:
- The newly created metric set for the given method.
-
newRequestCounterFor
Creates a new request counter for the given method.- Parameters:
method- The method to create the counter for.- Returns:
- The newly created request counter.
-
newResponseCounterFor
Creates a new response counter for the given method.- Parameters:
method- The method to create the counter for.- Returns:
- The newly created response counter.
-
asTimerFunction
protected Function<io.grpc.Status.Code,Timer> asTimerFunction(Supplier<Timer.Builder> timerTemplate)Creates a new timer function using the given template. This method initializes the default timers.- Parameters:
timerTemplate- The template to create the instances from.- Returns:
- The newly created function that returns a timer for a given code.
-
newTimerFunction
protected abstract 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.- Parameters:
method- The method to create the timer for.- Returns:
- The newly created function that returns a timer for a given code.
-