English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

SpringBoot Starter Actuator

SpringBoot ActuatorYes, it is a subproject of the Spring Boot framework. It includes many other features that can help us monitor and manage Spring Boot applications. It contains Actuator endpoints (the location of the resources). We can use HTTP and JMX Endpoint to manage and monitor Spring Boot applications. If you want to get production-ready features in your application, you should use S pring Boot Actuator.

Spring Boot Actuator features

Spring Boot Actuator has threeMain features:

Endpoints Metrics Audit

Endpoint: Actuator endpoints allow us to monitor and interact with the application. Spring Boot provides many built-in endpoints. We can also create our own endpoints. We can enable and disable each endpoint individually. Most applications choose HTTP , the endpoint ID and /actuator prefixmapped to URL.

For example, /health endpoints to provide basic health information of the application. By default, Actuator maps it to /actuator/health .

Metrics: Spring Boot Actuator integrates with MicrometerIntegrated to provide size metrics. Micrometer is integrated into Spring Boot. It is a tool library for supporting application metrics delivery from Spring. It is for applications with dimension data models Timers, gauges, counters, distribution summariesand Long task timerIt provides an interface that is independent of suppliers.

Audit: Spring Boot provides a flexible audit framework that publishes events to AuditEventRepository.If you are running spring-security, which will automatically publish authentication events.

Enable Spring Boot Actuator

We can enable Spring Boot Actuator by injecting dependencies into the pom.xml file spring-boot-starter-actuator to enable Actuator.

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

Spring Boot Actuator endpoints

Actuator endpoints allow us to monitor and interact with Spring Boot applications. Spring Boot includes many built-in endpoints, and we can also add custom endpoints to Spring Boot applications.

The following table describes widely used endpoints.

Id UsageDefault
ActuatorIt provides a hypermedia-basedDiscovery pageIt requires Spring HATEOAS to be on the classpath.true
auditeventsIt exposes the audit event information of the current application.true
autoconfigIt is used to display the auto-configuration report, which shows all candidates for auto-configuration and the reasons why they were "applied" or "not applied".true
beansIt is used to display the complete list of all Spring Beans in the application.true
configpropsIt is used to display a neatly organized list of all @ConfigurationProperties.true
dumpIt is used to perform thread dumps.true
envIt is used to expose properties from Spring's ConfigurableEnvironment.true
flywayIt is used to display all applied Flyway database migrations.true
healthIt is used to display the status information of the application.Error
infoIt is used to display arbitrary application information.Error
loggersIt is used to display and modify the configuration of the loggers in the application.true
liquibaseIt is used to display all applied Liquibase database migrations.true
metricsIt is used to display the metric information of the current application.true
mappingsIt is used to display a neatly organized list of all @RequestMapping paths.true
shutdownIt is used to allow a normal shutdown of the application.true
traceIt is used to display trace information.true

For Spring MVC, the following additional endpoints are used.

IdDescriptionDefault
docsIt is used to display documents, including example requests and responses for Actuator endpoints.Error
heapdumpIt is used to return GZip-compressed heap dump files.true
jolokiaIt is used to expose JMX beans over HTTP (when Jolokia is on the classpath).true
logfileIt is used to return the content of the log file.true
micrometerIt is used to expose metrics in a format that Prometheus server can scrape. It requires the dependency of Micrometer.-Prometheus.true

Spring Boot Actuator properties

Spring Boot provides security for all Actuator endpoints. It uses form-basedauthentication, based on user ID and authentication, which provides password. We can also access restricted Actuator endpoints by customizing basic authentication security for endpoints. We need to provide a password as a user, and offer a randomly generated management.security.roles Property overrides this configuration. For example:

management.security.enabled=true
management.security.roles=ADMIN
security.basic.enabled=true
security.user.name=admin
security.user.password=admin

Spring Boot Actuator example

Let's understand the concept of Actuator through an example.

Steps1: Open Spring Initializr https://start.spring.io/and create Maven project.

Steps2: provide groupname. We provide com.w3codebox.

Steps3: provide artifacts ID. We provide spring-boot-actuator-example.

Steps4: . Add the following dependencies: Spring Web, Spring Boot Starter Actuatorand Spring Data Rest HAL browser.

Steps5: click Generatebutton. When we click the "Generate" button, it will package all the specifications related to the project into Jar file, and download it to our local system.

Steps6: Extract the Jar file and paste it into the STS workspace.

Steps7: Import the project folder.

file->Import->Existing Maven project->Browse->Select folder spring-boot-actuator-example- >Complete

Importing may take some time. After importing the project, we can see the project directory in the "Package Explorer" section.

Steps8: : Create a Controller class. We have created a controller class named DemoRestController.

DemoRestController.java

package com.w3codebox;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class DemoRestController 
{
@GetMapping("/hello
public String hello() 
{
return "Hello User!";
}
}

Steps9: open application.properties file, and add the following statement to disable the security feature of Actuator.

application.properties

management.security.enabled=false

Steps10: Run SpringBootActuatorExampleApplication.java File.

Steps11: Open a browser and call the URL http: //localhost: 8080/actuator. It returns the following page:

{"_links":{"self":{"href":"http://localhost:8080/"actuator","templated":false},"health":{"href":"http://localhost:8080/actuator/"health","templated":false},"health-"path":{"href":"http://localhost:8080/actuator/health/{*path","templated":true},"info":{"href":"http://localhost:8080/actuator/"info","templated":false}}}

By default, the application runs on port8080 after the Actuator starts, we can see the list of all endpoints exposed via HTTP.

Let's call the URL http: //localhost: 8080/to call health Endpoints. Actuator/Health status. It indicates the status UP . This indicates that the application is running normally and is functioning properly.

Similarly, we can call other endpoints to help us monitor and manage Spring Boot applications.