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:

gRPC A66 Metrics

In addition to above listed metrics, once the dependencies are added grpc-spring-boot-starter will automatically configure to gather gRPC A66 metrics.

Client Metrics

Counter

Distribution

Timer

Server Metrics

Counter

Distribution

Timer

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.

GRPC Health

By default, the health endpoint will use the standard gRPC implementation for health, which does not integrate with Spring Boot Actuator.

The server provides an optional integration with Actuator health information using the gRPC Health API.

This integration enables the server to respond to gRPC health checks based on the HealthEndpoint from Actuator, which is the same used for the web version.

To enable this integration, add the following properties to your application configuration:

grpc.server.health-service.type=ACTUATOR

The integration allows you to check the health status for the whole service or specific health indicators, where the service is the key of the HealthIndicator. Watch is not yet supported because actuator is pull-based and does not automatically tries to determine the status of the service to notify clients.

To prevent any health service from being served by the GRPC server, you can set the type to NONE:

grpc.server.health-service.type=NONE

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

You can opt out from collecting gRPC A66 metrics using grpc.metricsA66Enabled=false.


<- Back to Index