Posts Spring Boot Actuator To Check Health Of MicroService In Production
Post
Cancel

Spring Boot Actuator To Check Health Of MicroService In Production

Spring Boot includes a number of additional features to help you monitor and manage your application when you push it to production. You can choose to manage and monitor your application by using HTTP endpoints or with JMX. Auditing, health, and metrics gathering can also be automatically applied to your application.

Spring Boot includes a number of built-in endpoints, and you can also add your own or even configure existing endpoints to be exposed on any custom endpoints of your choice. It is obvious that all the endpoints cannot be exposed publicly, considering that there are many sensitive endpoints like beans, env, etc. Hence, Spring Boot also sets sensitive defaults to true for many endpoints that require a username/password when they are accessed over HTTP (or simply disabled if web security is not enabled). Health and info are not sensitive by default.

Enabling Production-ready Features

This is easy. You only need to include the following dependency in your project.

To add the actuator to a Maven based project, add the following ‘Starter’ dependency:

1
2
3
4
5
6
7
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
</dependencies>

For Gradle, use the following declaration.

1
2
3
4
dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-actuator'
}

Spring provides several useful health indicators based on the dependencies you add to the project. Below are some of the predefined health indicators.

  • DataSourceHealthIndicator
  • MongoHealthIndicator
  • Neo4jHealthIndicator
  • CassandraHealthIndicator
  • RedisHealthIndicator
  • CassandraHealthIndicator
  • RabbitHealthIndicator
  • CouchbaseHealthIndicator
  • DiskSpaceHealthIndicator
  • ElasticsearchHealthIndicator
  • InfluxDbHealthIndicator
  • JmsHealthIndicator
  • MailHealthIndicator
  • SolrHealthIndicator

You can also implement your own health indicators.

This post is licensed under CC BY 4.0 by the author.