info and health endpoints in spring boot info and health endpoints in spring boot

In spring boot microservices based application, where microservices talks to each other using RESTFul APIs. We can expose some important information about microservice such as name, version, description over some endpoints say /info and also realtime status or health over some endpoint say /health to create application dashboards, realtime alerts, track microservice updates and so on…

Actuator

Good news is that both endpoints come out of the box with Spring Boot Actuator. To enable this, just add spring-boot-starter-actuator dependency in your spring boot application.

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


When you start your application after adding actuator dependency, You will see following in the startup logs that actuator exposed two endpoints i.e. /actuator/info and /actuator/health

2020-04-20 18:36:12.881 INFO [main] o.s.b.a.e.web.EndpointLinksResolver: Exposing 2 endpoint(s) beneath base path '/actuator'


/actuator/info endpoint

(info endpoint with no data)

(info endpoint with no data)

We see that initially /actuator/info endpoint gives an empty JSON. We will now add some properties related to app info.

application.yml
info:
  app:
    name: spring boot microservice
    version: 1.0.0_RELEASE
    description: more details about sprint boot microservice
    contact-support: apisupportgroup@abc.com
  copyright: copyright (c) abc.com
  license: MIT
  tech-used:
    - name: java
      version: 11.x
    - name: spring-boot
      version: 2.x


That’s all we need to do to make this data available on the /actuator/info endpoint. Spring will automatically add all the properties prefixed with info to the endpoint.

(info endpoint with app info)

(info endpoint with app info)

/actuator/info endpoint can be used to -

  • create a dashboard of microservices info
  • check for version update of particular microservice and so and so forth…


/actuator/health endpoint

By default endpoint show the current status of the running application.

(health endpoint with status up and running)

(health endpoint with status up and running)

/actuator/health endpoint can be used to -

  • create a dashboard of microservices with realtime status
  • check the heartbeat of microservice and so and so forth…