liveBook · Manning

Actuator endpoint

As explained in Spring in Action, Sixth Edition

An Actuator endpoint is a Spring Boot Actuator management interface that exposes operational data or operations through supported communication mechanisms.

An Actuator endpoint lets you inspect or influence a running Spring Boot application. Add the Actuator starter to make built-in endpoints available. They report information such as health, configuration, and metrics; some also accept operations that change the running application. Endpoints are available over HTTP and, with the exception of /heapdump, as JMX MBeans. section 15.1 section 15.5

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

Add this dependency to a Maven pom.xml to equip a Spring Boot application with Actuator endpoints. section 15.1

HTTP endpoint paths start with /actuator by default: GET /actuator/health requests health information. Set management.endpoints.web.base-path to change the prefix, for example to /management. Only /health is exposed by default in this setup; opt in to other web endpoints deliberately because they can reveal sensitive information. section 15.1.1 section 15.1.2

management:
  endpoints:
    web:
      exposure:
        include: health,info,beans,conditions

This YAML exposes just health, info, beans, and conditions. Use management.endpoints.web.exposure.include and exclude to control which web endpoints are exposed. section 15.1.2

Choose an endpoint for the question you need to answer:

  • /health reports application health; /info can provide build and Git commit details. section 15.1 section 15.5
  • /beans describes application-context beans; /conditions reports which autoconfiguration conditions passed or failed. section 15.1
  • /metrics provides runtime measurements; /env and /loggers can support changes to a running application’s configuration. section 15.2.4 section 15.5

Find a request metric

Use curl to GET /actuator and discover links to exposed endpoints. Then GET /actuator/metrics/http.server.requests for request counts and timings. Add tag=status:404 to narrow the measurements to 404 responses; available tags narrow along with the results. section 15.2 section 15.2.4

A custom endpoint is not an ordinary Spring MVC controller. Annotate a component class with @Endpoint(id="notes"), then mark its methods with @ReadOperation, @WriteOperation, or @DeleteOperation. A notes endpoint can use those operations to list, add, and remove notes. The annotations describe operations without tying the class to HTTP alone. section 15.3.4

Secure exposed endpoints with Spring Security, especially those that reveal details or permit changes. EndpointRequest.toAnyEndpoint() matches Actuator endpoints without hardcoding /actuator/**, so the rule can survive a base-path change. For a friendlier view of endpoint data, Spring Boot Admin can consume it and display it in a web application. section 15.4 section 16.4

How Spring in Action, Sixth Edition covers it

How deep it goes
Works through starter setup, exposure, HTTP consumption, custom operation annotations, and security while deferring detailed JMX treatment.
Examples
Uses curl requests for tagged HTTP request metrics and a custom notes endpoint with read, write, and delete operations.
What it assumes
Assumes a Spring Boot application and teaches Actuator setup by adding its starter dependency.
What you can do after
Build it from scratch with @Endpoint and annotated read, write, and delete operations.
How it connects
Connects application health, runtime metrics, Spring Security, JMX MBeans, and Spring Boot Admin.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring in Action, Sixth Edition. The section links point to the parts of the book it draws on.