Skip to main content

Spring Actuator

What is an actuator?

It is app monitoring tool for health check applications user some endpoint urls.
Monitoring our app, gathering metrics, understanding traffic or the state of our database
becomes trivial with this dependency.
The main benefit of this library is that we can get production grade tools without having to actually implement these features ourselves.
Actuator is mainly used to expose operational information about the running application
 health, metrics, info, dump, env, etc. It uses HTTP endpoints or JMX beans to enable us to 
interact with it.
Once this dependency is on the classpath several endpoints are available for us out of the box. 
As with most Spring modules, we can easily configure or extend it in many ways.

Problem

  • How can I monitor and manage my application?
  • How can I check the application's health?
  • How can I access application metrics?

Solution: Spring Boot Actuator

  • Exposes endpoints to monitor and manage your application
  • You easily get DevOps functionality out-of-the-box
  • Simply add the dependency to your POM file
  • REST endpoints are automatically added to your application

                                                                           

Spring Boot Actuator

Adding the dependency to your POM file

Endpoints are prefixed with: /actuator

ID
Description
auditevents
Exposes audit events information for the current application. Requires an  
AuditEventRepository bean.
beans
Displays a complete list of all the Spring beans in your application.
caches
Exposes available caches.
conditions
Shows the conditions that were evaluated on configuration and auto-configuration 
classes and the reasons why they did or did not match.
configprops
Displays a collated list of all @ConfigurationProperties.
env
Exposes properties from Spring’s ConfigurableEnvironment.
flyway
Shows any Flyway database migrations that have been applied. Requires one or more 
 Flyway beans.
health
Shows application health information.
httptrace
Displays HTTP trace information (by default, the last 100 HTTP request-response 
exchanges). Requires an HttpTraceRepository bean.
info
Displays arbitrary application info.
integrationgraph
Shows the Spring Integration graph. Requires a dependency on spring-integration-core.
loggers
Shows and modifies the configuration of loggers in the application.
liquibase
Shows any Liquibase database migrations that have been applied. Requires one or more  
Liquibase beans.
metrics
Shows ‘metrics’ information for the current application.
mappings
Displays a collated list of all @RequestMapping paths.
scheduledtasks
Displays the scheduled tasks in your application.
sessions
Allows retrieval and deletion of user sessions from a Spring Session-backed session store. Requires a Servlet-based web application using Spring Session.
shutdown
Lets the application be gracefully shutdown. Disabled by default.
threaddump
Performs a thread dump.

If your application is a web application (Spring MVC, Spring WebFlux, or Jersey), you can use
 the following additional endpoints:

ID
Description
heapdump
Returns an hprof heap dump file.
jolokia
Exposes JMX beans over HTTP (when Jolokia is on the classpath, not available for WebFlux).
Requires a dependency on jolokia-core.
logfile
Returns the contents of the logfile (if logging.file.name or logging.file.path properties have
been set). Supports the use of the HTTP Range header to retrieve part of the log file’s content.
prometheus
Exposes metrics in a format that can be scraped by a Prometheus server. Requires a dependency
on micrometer-registry-prometheus.

Exposing Endpoints
  • By default, only /health and /info are exposed
  • To expose all actuator endpoints over HTTP

Spring Boot Actuator - Security


What about Security?
You may NOT want to expose all of this information

You may NOT want to expose all of this information
• Add Spring Security to project and endpoints are secured :-)


Customizing Spring Security

  • You can customize Spring Security for Spring Boot Actuator
  • Use a database for roles, encrypted passwords etc

Follow the same techniques as regular Spring Security

Excluding Endpoints

  • To exclude /health and /info



Comments