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.
Spring Dependencies
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"}
There are many differences, but here are some typical things you may encounter when migrating from 1.x to 2.x.
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
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
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.
Recommended Posts