Spring Boot | エンドポイント
エンドポイント
依存関係にspring-boot-starter-actuatorを追加すると、システムの状態をWeb APIで取得できます。
build.gradle
dependencies {
compile 'org.springframework.boot:spring-boot-starter-web'
compile 'org.springframework.boot:spring-boot-starter-actuator'
}
Main.java
package sample.springboot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Main {
public static void main(String[] args) throws Exception {
SpringApplication.run(Main.class, args);
}
}
アプリケーションを起動し、いくつかのURLにアクセスします。
$ curl http://localhost:8080/health
{"status":"UP"}
$ curl http://localhost:8080/metrics
{"mem":253440,"mem.free":127785,"processors":8,"instance.uptime":51033,"uptime":53546,"systemload.average":-1.0,"heap.committed":253440,"heap.init":262144,"heap.used":125654,"heap":3717632,"threads.peak":16,"threads.daemon":14,"threads":16,"classes":5490,"classes.loaded":5490,"classes.unloaded":0,"gc.ps_scavenge.count":3,"gc.ps_scavenge.time":39,"gc.ps_marksweep.count":1,"gc.ps_marksweep.time":44,"httpsessions.max":-1,"httpsessions.active":0,"counter.status.200.health":1,"counter.status.200.metrics":1,"gauge.response.health":47.0,"gauge.response.metrics":23.0}
以下はエンドポイントの一覧です。
| id | 説明 |
|---|---|
| dump | スレッドダンプ |
| env | システムプロパティ、環境変数、プロパティファイルの設定など |
| health | アプリケーションの状態 |
| metrics | メモリー使用量、スレッド数、ガベージコレクション回数など |
| trace | 最近のアクセス履歴 |
| shutdown | POSTメソッドでアクセスするとアプリケーションを停止します。デフォルトでは無効です。 |
その他のエンドポイントもあります。