Spring Boot 2 actuator

pom.xml

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

application.properties

By default, only health,info,metrics are enabled.
To enable all others :

management.endpoints.web.exposure.include=*

Actuators

/beans : Displays a complete list of all the Spring beans in your application.
/cache : Exposes available caches.
/configprops : Displays a collated list of all @ConfigurationProperties.
/env : Exposes properties from Spring’s ConfigurableEnvironment.
/health : Shows application health information.
/httptrace : Displays HTTP trace information (by default, the last 100 HTTP request-response exchanges). Requires an HttpTraceRepository bean.
/loggers : Shows and modifies the configuration of loggers in the application.
/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.
/threaddump : Performs a thread dump.

acess uri

/actuator/fooEndPoint

How to enable all actuators in Spring Boot 2.2+

Since Spring Boot 2.2, by default, some are disabled such as httptraces or shutdown. 
To enable all of them  :
management.endpoints.web.exposure.include=*
Warning : including all actuators is not enough for « protected » actuators that are disabled by default such as the shutdown actuator.

How to enable httptraces actuator in Spring Boot 2.2+

We need to include it or all (as seen above)  :
But we also need to register a httpTraceRepository bean :

import org.springframework.boot.actuate.trace.http.HttpTraceRepository;
import org.springframework.boot.actuate.trace.http.InMemoryHttpTraceRepository;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
 
@Configuration
public class HttpTraceActuatorConfiguration {
 
    @Bean
    public HttpTraceRepository httpTraceRepository() {
        return new InMemoryHttpTraceRepository();
    }
 
}

How to use the loggers actuator

To change dynamically a logger level (for a package or class) :
curl -v "http://foobar:8080/actuator/loggers/my.package.bar.MyClass" -H "Content-Type: application/json" -d $'{ "configuredLevel": "DEBUG" }'

The health actuator

By default, only the status (UP or not) of the app is rendered.
To get more information (especially the disk space), we could specify a property for that endpoint :
endpoint.health.show-details: always to display it for anybody.
endpoint.health.show-details: when_authorized to display it for users authorized for that actuator.

How to enable and use the shutdown actuator in Spring Boot 2.2+

We need to include it or all (as seen above) . 
But we also need to enable it :
management.endpoint.shutdown.enabled=true
Optionally we could set the shutdown type and the timeout before force resources shutdown :
Example :

server.shutdown: graceful # Type of shutdown that the server performs. Default immediate
spring.lifecycle.timeout-per-shutdown-phase: 40s # Timeout for the shutdown of any phase. Default 30s

How to use it ?
The actuator has to be called with a POST request such as :
curl -X POST "http://localhost:8090/actuator/shutdown"

Trace actuator

Identify all mappings :
curl "http://localhost:8888/actuator/mappings" | grep -P -o "\"patterns\":.*?]"

Disable security for actuator

public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
// ...
  @Override
  protected void configure(HttpSecurity http) throws Exception {
    http.authorizeRequests()
        .antMatchers("/actuator", "/actuator/*")
        .permitAll();
    // ...
   }
// ...
}
Ce contenu a été publié dans Non classé. Vous pouvez le mettre en favoris avec ce permalien.

Laisser un commentaire

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *