Skip to content

Latest commit

 

History

History

livelessons-operations-monitoring

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Lesson 3: Creating Operations-Friendly Microservices (Monitoring)

Introduction

This sample provides an introduction to the monitor support built into Spring Boot.

Building and running the sample

Use the following commands to build run the application:

$ mvn clean package
$ java -jar target/livelessons-operations-actuator-1.0.0-SNAPSHOT.jar

Check the health of the application by hitting the /health endpoint.

Understanding the code

This sample demonstrates a custom HealthIndicator and HealthAgregator. It also shows how you can remap status code responses.

Exposing full health information

By default Spring Boot doesn’t expose all the information used tell if an application is healthy, you just get a single status response. This application has endpoints.health.sensitive set to false to show all information in the JSON.

Custom HealthIndicator

You can easily write your own HealthIndicator to extend the standard ones provided by Spring Boot. The ExampleHealthIndicator in this project randomly returns up or outOfService. Refresh your browser several times on the /info endpoint and you should see the health toggle.

Custom HealthAggregator

The HealthAggregator interface is responsible for combining all health results into a single response. In this project we have a ExampleHealthAgregator which re-orders which status has the highest priority.

Custom HTTP status mapping

By default Spring Boot will map OK status to HTTP 200 and DOWN or OUT_OF_SERVICE to HTTP 503. You can customize this in the application properties. This sample uses:

endpoints.health.mapping.OUT_OF_SERVICE=i-am-a-teapot

To remap OUT_OF_SERVICE to HTTP 418 (an IETF April Fools' joke in RFC 2324)