Spring Boot Actuator: Overview and Getting Started


On this page, we’ll discuss the Spring Boot actuator overview and how to integrate/getting started with it.

1. Overview

Spring Boot Actuator is production-ready Spring Boot sub-module/project to monitor the health, performance, running processes, etc of Spring Boot application. It provides the numbers of pre-defined endpoints to access that information of the application. We can use HTTP and JMX endpoints to manage and monitor the application.

Definition of Actuator

An actuator is a manufacturing term that refers to a mechanical device for moving or controlling something. Actuators can generate a large amount of motion from a small change.

Source: docs.spring.io

1.1 Features

Spring Boot Actuator has three main features for the production-ready application:

  1. Auditing
  2. Health/Endpoints
  3. Metrics

and these features are automatically applied to your application.

2. Getting Started

To enable Spring Boot Actuator features in your application, you only need to add spring-boot-starter-actuator dependency.

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

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

For Gradle, use the following declaration:

dependencies {
    compile("org.springframework.boot:spring-boot-starter-actuator")
}

By adding the above dependency, we are done☺

2.1 Create Project

To test the Spring Boot Actuator features, you will need to create a brand new Spring Boot project and add all your required dependencies, make sure you have added spring-boot-starter-actuator dependency.

2.2 In-Built Endpoints

Well, by adding spring-boot-starter-actuator dependency, a bunch of in-built endpoints automatically added to your application. For example:

  • health – Shows application health information.
  • info – Displays arbitrary application info.
  • env – Exposes properties from Spring’s ConfigurableEnvironment.
  • metrics – Shows ‘metrics’ information for the current application.
  • mappings –  Displays a collated list of all @RequestMapping paths.
  • And many more, check out all Endpoints

Note:

  1. All the endpoint along with a prefix of /actuator is mapped to a URL. For example, by default, the health endpoint is mapped to /actuator/health.
  2. All the endpoints are disabled to access directly for security reasons except health and info. Because of all the endpoints display the sensitive information of the application.

2.3 Actuator Configuration

Spring Boot Actuator configuration properties can be configured/managed by application.properties file. It will help when we have exposed the same endpoint in the application or enable/disable some actuator endpoints or change the port where the actuator will run.

By default, Spring Boot Actuator runs on the same port where the application is deployed.

The actuator configuration properties key stated with management.

application.properties
# Spring Boot Actuator Configuration

# Set port
management.server.port=9090

# Enable all endpoints to be accessed (bypassing the security)
management.endpoints.web.exposure.include=*

#Enable all except env and beans
management.endpoints.web.exposure.exclude=env,beans

And there are numbers of properties available to configure actuator in Spring Boot application.

2.4 Test the Application

Start your brand new created application here we go.

1. /actuator/health

{
    "status": "UP"
}

2. /actuator/loggers

{
    "levels": [
        "OFF",
        "ERROR",
        "WARN",
        "INFO",
        "DEBUG",
        "TRACE"
    ],
	...............
	...............
	...............
	...............
    "groups": {
        "web": {
            "configuredLevel": null,
            "members": [
                "org.springframework.core.codec",
                "org.springframework.http",
                "org.springframework.web",
                "org.springframework.boot.actuate.endpoint.web",
                "org.springframework.boot.web.servlet.ServletContextInitializerBeans"
            ]
        },
        "sql": {
            "configuredLevel": null,
            "members": [
                "org.springframework.jdbc.core",
                "org.hibernate.SQL",
                "org.jooq.tools.LoggerListener"
            ]
        }
    }
}

Rest you can try in your browser 🙂

References

  1. Spring Boot Actuator: Production-ready Features
  2. Building a RESTful Web Service with Spring Boot Actuator

Similar Posts

About the Author

Atul Rai
I love sharing my experiments and ideas with everyone by writing articles on the latest technological trends. Read all published posts by Atul Rai.