Class MetricCollectingServerInterceptor
java.lang.Object
io.micrometer.core.instrument.binder.grpc.AbstractMetricCollectingInterceptor
io.micrometer.core.instrument.binder.grpc.MetricCollectingServerInterceptor
- All Implemented Interfaces:
io.grpc.ServerInterceptor
public class MetricCollectingServerInterceptor
extends AbstractMetricCollectingInterceptor
implements io.grpc.ServerInterceptor
A gRPC server interceptor that will collect metrics using the given
MeterRegistry
.
Usage:
Server server = ServerBuilder.forPort(8080) .intercept(new MetricCollectingServerInterceptor(meterRegistry)) .build(); server.start()
- 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
ConstructorDescriptionCreates a new gRPC server interceptor that will collect metrics into the givenMeterRegistry
.MetricCollectingServerInterceptor
(MeterRegistry registry, UnaryOperator<Counter.Builder> counterCustomizer, UnaryOperator<Timer.Builder> timerCustomizer, io.grpc.Status.Code... eagerInitializedCodes) Creates a new gRPC server interceptor that will collect metrics into the givenMeterRegistry
and uses the given customizers to configure theCounter
s andTimer
s. -
Method Summary
Modifier and TypeMethodDescription<Q,
A> io.grpc.ServerCall.Listener<Q> interceptCall
(io.grpc.ServerCall<Q, A> call, io.grpc.Metadata requestHeaders, io.grpc.ServerCallHandler<Q, A> next) protected Counter
newRequestCounterFor
(io.grpc.MethodDescriptor<?, ?> method) Creates a new request counter for the given method.protected Counter
newResponseCounterFor
(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.void
preregisterService
(io.grpc.BindableService service) Pre-registers the all methods provided by the given service.void
preregisterService
(io.grpc.ServerServiceDefinition serviceDefinition) Pre-registers the all methods provided by the given service.Methods inherited from class io.micrometer.core.instrument.binder.grpc.AbstractMetricCollectingInterceptor
asTimerFunction, metricsFor, newMetricsFor, prepareCounterFor, prepareTimerFor, preregisterMethod, preregisterService
-
Constructor Details
-
MetricCollectingServerInterceptor
Creates a new gRPC server interceptor that will collect metrics into the givenMeterRegistry
.- Parameters:
registry
- The registry to use.
-
MetricCollectingServerInterceptor
public MetricCollectingServerInterceptor(MeterRegistry registry, UnaryOperator<Counter.Builder> counterCustomizer, UnaryOperator<Timer.Builder> timerCustomizer, io.grpc.Status.Code... eagerInitializedCodes) Creates a new gRPC server interceptor that will collect metrics into the givenMeterRegistry
and uses the given customizers to configure theCounter
s andTimer
s.- 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
-
preregisterService
public void preregisterService(io.grpc.BindableService 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:
-
preregisterService
public void preregisterService(io.grpc.ServerServiceDefinition serviceDefinition) Pre-registers the all methods provided by the given service. This will initialize all default counters and timers for those methods.- Parameters:
serviceDefinition
- The service to initialize the meters for.- See Also:
-
newRequestCounterFor
Description copied from class:AbstractMetricCollectingInterceptor
Creates a new request counter for the given method.- Specified by:
newRequestCounterFor
in classAbstractMetricCollectingInterceptor
- Parameters:
method
- The method to create the counter for.- Returns:
- The newly created request counter.
-
newResponseCounterFor
Description copied from class:AbstractMetricCollectingInterceptor
Creates a new response counter for the given method.- Specified by:
newResponseCounterFor
in classAbstractMetricCollectingInterceptor
- 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 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.ServerCall.Listener<Q> interceptCall(io.grpc.ServerCall<Q, A> call, io.grpc.Metadata requestHeaders, io.grpc.ServerCallHandler<Q, A> next) - Specified by:
interceptCall
in interfaceio.grpc.ServerInterceptor
-