Skip to the content.

Spring Boot Actuator Support

<- Back to Index

This page focuses on the integration with Spring-Boot-Actuator. This is an optional feature. Supported features:

Table of Contents

Dependencies

The metric collection and other actuator features are optional, they will be enabled automatically if a MeterRegistry is in the application context.

You can achieve this simply by adding the following dependency to Maven:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

or to Gradle:

compile("org.springframework.boot:spring-boot-starter-actuator")

Note: In most cases you will also need the spring-boot-web dependency in order to actually view the metrics. Please note that spring-boot-web runs on a different port than the grpc server (usually 8080). If you don’t want to add a web-server you can still access the metrics via JMX (if enabled).

Metrics

Once the dependencies are added grpc-spring-boot-starter will automatically configure ClientInterceptors/ServerInterceptors that will gather the metrics.

Counter

Tags:

Timer

Tags:

Viewing the metrics

You can view the grpc metrics along with your other metrics at /actuator/metrics (requires a web-server) or via JMX.

Note: You might have to enable your metrics endpoint first.

management.endpoints.web.exposure.include=metrics
#management.endpoints.jmx.exposure.include=metrics
management.endpoint.metrics.enabled=true

Read the official documentation for more information about Spring Boot Actuator.

Metric configuration

By default, the client will only create metrics for calls that have been made. However, the server will try to find all registered services and initialize metrics for them.

You can customize the behavior by overwriting the beans. The following demonstrates this using the MetricCollectingClientInterceptor:

@Bean
MetricCollectingClientInterceptor metricCollectingClientInterceptor(MeterRegistry registry) {
    MetricCollectingClientInterceptor collector = new MetricCollectingClientInterceptor(registry,
            counter -> counter.tag("app", "myApp"), // Customize the Counters
            timer -> timer.tag("app", "myApp"), // Customize the Timers
            Code.OK, Code.INVALID_ARGUMENT, Code.UNAUTHENTICATED); // Eagerly initialized status codes
    // Pre-generate metrics for some services (to avoid missing metrics after restarts)
    collector.preregisterService(MyServiceGrpc.getServiceDescriptor());
    return collector;
}

InfoContributor

(Server only)

The server part automatically configures an InfoContributor that publishes the following information:

You can view the grpc info along with your other info at /actuator/info (requires a web-server) or via JMX.

Note: You might have to enable your info endpoint first.

management.endpoints.web.exposure.include=info
#management.endpoints.jmx.exposure.include=info
management.endpoint.info.enabled=true

You can turn of the service listing (for both actuator and grpc) using grpc.server.reflectionServiceEnabled=false.

Opt-Out

You can opt out from the actuator autoconfiguration using the following annotation:

@EnableAutoConfiguration(exclude = {GrpcClientMetricAutoConfiguration.class, GrpcServerMetricAutoConfiguration.class})

or using properties:

spring.autoconfigure.exclude=\
net.devh.boot.grpc.client.autoconfigure.GrpcClientMetricAutoConfiguration,\
net.devh.boot.grpc.server.autoconfigure.GrpcServerMetricAutoConfiguration

<- Back to Index