Alejandro Duarte

Health monitoring

In previous parts of this tutorial, we discussed high availability and fault tolerance techniques that make services resilient to external failures. In this chapter, we’ll add health endpoints and a dashboard to visually monitor service status.

Why do we need this?

Microservices provide benefits. However, they come with costs. An evident cost of microservices is the increase in complexity. With more parts in a system, the challenge to fully understand and troubleshoot performance problems grows. Monitoring health in microservices helps to understand the overall performance of the system and detect individual points of failure.

How does it work?

Microservices expose health endpoints with information about the status of the service. A monitor application keeps track of this data, aggregates it, and presents the result in a dashboard. For example, the admin-application exposes a health endpoint at /actuator/health. If you have an instance running on port 9101, you can request http://localhost:9101/actuator/health to see health information similar to the following:

Health endpoint
You can see a list with the endpoints that are available at http://localhost:9101/actuator/.

Enabling health endpoints with Spring Boot Actuator

Spring Boot includes many endpoints. You can enable all of them by adding the following to your configuration file:

management.endpoints.web.exposure.include: "*"

The demo application enables all the endpoints for the biz-application, the admin-application, the news-application, the website-application, the proxy-server, and the monitor-application itself.

Implementing a monitor dashboard

Use the Spring Initializr to create a new Spring Boot application named monitor-application and include the Config client, Hystrix Dashboard, Turbine, Actuator, Retry, Aspects, and DevTools (optional) dependencies:

Spring Initializr

Open up the MonitorApplication class and enable the Hystrix Dashboard by using the following annotations:

public class MonitorApplication {

Remove the file and create a new bootstrap.yml file with the following content:

server.port: 8201

spring: monitor-application
      enabled: true
      serviceId: config-server
    fail-fast: true
      initialInterval: 2000
      maxAttempts: 30

      defaultZone: http://localhost:8001/eureka/
    registryFetchIntervalSeconds: 1
    leaseRenewalIntervalInSeconds: 1

Add a new monitor-application.yml file to your external configuration with the following content:

  appConfig: biz-application, admin-application, news-application, proxy-server
  clusterNameExpression: "'default'"
  instanceUrlSuffix: actuator/

This configures an aggregator (Turbine) for the health stats from the biz-application, admin-application, news-application, and `proxy-service services.

Make sure you are running all the services of the demo application, and compile and run the monitor-application by executing the following in the command line:

cd vaadin-microservices-demo/monitor-application

java -jar target/monitor-application-0.0.1-SNAPSHOT.jar

Point your browser to http://localhost:8201/hystrix and introduce http://localhost:8201/ as the stream URL. Click the Monitor Stream button to see a dashboard like the following:


Try using all the features of the application (http://localhost:8080) and shutting down some services to see how the dashboard reacts.

What’s next?

Always keep in mind that microservices introduce complexity in order to solve problems in big applications with multiple teams. Don’t discard a monolithic approach if you are not facing such problems.

Although there’s much more to talk about in microservices, I hope this tutorial gave you an idea of some of the key concepts, patterns, and challenges you may encounter when using them.

Vaadin is an open-source framework offering the fastest way to build web apps on Java backends

Comments (1)