In a previous post we learned how to add build information to the
/info endpoint in our application. We can add custom information to the
/info endpoint via our application configuration or via a bean by implementing the
InfoSource interface. Remember we need to add the
io.micronaut:management dependency to our application for this feature.
When we add the
io.micronaut:management dependency to our Micronaut application we get, among other things, a
/health endpoint. We must enable it in our application configuration where we can also configure how much information is shown and if we want to secure the endpoint. Micronaut has some built-in health indicators, some of which are only available based on certain conditions. For example there is a disk space health indicator that will return a status of DOWN when the free disk space is less than a (configurable) threshold. If we would have one or more
DataSource beans for database access in our application context a health indicator is added as well to show if the database(s) are available or not.
We can also add our own health indicator that will show up in the
/health endpoint. We must write a class that implements the
HealthIndicator interface and add it to the application context. We could add some conditions to make sure the bean is loaded when needed. Micronaut also has the abstract
AbstractHealthIndicator class that can be used as base class for writing custom health indicators.
Micronaut has some built-in management endpoints to get information, a list of beans, health checks and more. To enable the endpoints we must add the dependency
io.micronaut:management to our application. Then we can add configuration properties to enable the different endpoints. The
/info endpoint gathers information from several sources with properties. If we want to add build information we must create a file
build-info.properties with information and Micronaut will automatically add the properties from the file to the