[JAVA] Spring with Kotorin --- 5. Actuator

Overview / Description

I've been touching Spring Boot up to Spring with Kotorin-- 4. REST API Design. From the point of view of running the application, I saw the procedure to make it work, although it is very simple. On the other hand, nothing is done from the perspective of monitoring the application. In Spring Boot, there is ** Actuator ** as a function to easily implement a monitoring tool, so I will try using it.

By the way, the version of Spring Boot used here was ** 2.x series **. There are various improvements and differences between the 1.x series and the 2.x series. The Actuator I'm trying to use this time also has differences between the 1.x series and the 2.x series, so I would like to see the differences as well.

Assumptions / Environment

Runtime version

Spring Dependencies

Development environment

Procedure / Explanation

Use of Spring Actuator

To enable the Spring Actuator, define the following dependency in build.gradle.

implementation('org.springframework.boot:spring-boot-starter-actuator')

You can use it only with this. After that, access the endpoint described in the following document "Endpoints" By doing so, you will be able to obtain various information via HTTP.

Example: HEALTH

$ curl 'http://localhost:8080/actuator/health' -i -X GET

HTTP/1.1 200
Content-Type: application/vnd.spring-boot.actuator.v2+json;charset=UTF-8
Transfer-Encoding: chunked
Date: Sun, 11 Nov 2018 13:08:00 GMT

{"status":"UP"}

Difference between Spring 1.x and 2.x

There are many differences, but here are some typical things you may encounter when migrating from 1.x to 2.x.

Access base path

In 1.x, the endpoint was accessed directly to display the information. : http: // localhost: 8080 / health In 2.x, access is performed by specifying the base path before the endpoint. : http: // localhost: 8080 / <base path> / health

By default, the base path is ** / actuator **.

To change it, define it in the configuration file (application.yml). You can change the base perspective by defining it as follows. In the example below, the base path is / admin.

management:
  endpoints:
    web:
      base-path: /admin

Public endpoint

In 1.x, endpoints were pre-published. In 2.x, the only exposed endpoints are / health and / info. -> Reference

Even in 2.x, to publish everything in advance, define it in the configuration file (application.yml) as follows.

management:
  endpoints:
    web:
      exposure:
        include: "*"

In the example, the publication target is specified by asterics (\ *), but if you specify it individually, you can publish it by describing the target endpoint.

        include: beans, env

Summary / Looking back

Actuator is a handy tool that you can use just by adding dependencies. Therefore, I think that there are opportunities to use it in many situations, but since the access method and target between 1.x series and 2.x series have changed, when migrating to 2.x series, I want to be careful not to get 404.

This source

Recommended Posts

Spring with Kotorin --- 5. Actuator
Spring with Kotorin ―― 1. SPRING INITIALIZR
Spring with Kotorin --8 Repository layer
Spring with Kotorin --6 Asynchronous processing
Spring with Kotorin ―― 7. Service layer
Spring with Kotorin --4 REST API design
Spring with Kotorin --9 Database migration --Flyway
Spring with Kotorin --8 Repository layer --Supplement: H2 Database
Self-made Validation with Spring
With Kotorin ―― 7. Scoping Function
Download with Spring Boot
Spring with Kotorin --3. Omitting curly braces from the function
Generate barcode with Spring Boot
Hello World with Spring Boot
Java Config with Spring MVC
Get started with Spring boot
Hello World with Spring Boot!
Run LIFF with Spring Boot
SNS login with Spring Boot
File upload with Spring Boot
Spring Boot starting with copy
Login function with Spring Security
Using Mapper with Java (Spring)
Spring Boot starting with Docker
Hello World with Spring Boot
Set cookies with Spring Boot
Use Spring JDBC with Spring Boot
Add module with Spring Boot
Getting Started with Spring Boot
Link API with Spring + Vue.js
Create microservices with Spring Boot
Send email with spring boot
Use Basic Authentication with Spring Boot
Implemented authentication function with Spring Security ②
gRPC on Spring Boot with grpc-spring-boot-starter
Hot deploy with Spring Boot development
Spring Boot programming with VS Code
Spring Boot Actuator logback_events_total metric value
Until "Hello World" with Spring Boot
Inquiry application creation with Spring Boot
Implemented authentication function with Spring Security ①
Get validation results with Spring Boot
Implement file download with Spring MVC
Oauth2 authentication with Spring Cloud Gateway
(Intellij) Hello World with Spring Boot
Create an app with Spring Boot
Google Cloud Platform with Spring Boot 2.0.0
Check date correlation with Spring Boot
I tried GraphQL with Spring Boot
[Java] LINE integration with Spring Boot
[Spring] Autowired multiple beans. (With bonus)
Beginning with Spring Boot 0. Use Spring CLI
I tried Flyway with Spring Boot
Authentication / authorization with Spring Security & Thymeleaf
Test Spring framework controller with Junit
Message cooperation started with Spring Boot
Spring Boot gradle build with Docker
Processing at application startup with Spring Boot
OR search with Spring Data Jpa Specification
Hello World with Eclipse + Spring Boot + Maven
Create a simple on-demand batch with Spring Batch