4
5

More than 5 years have passed since last update.

Spring Boot 2で/actuator/prometheusを有効にする

Last updated at Posted at 2018-03-03

経緯

Spring Boot 2ではメトリクス機能の強化によりPrometheusにも対応をしていますが、公式リファレンス通りにやってもうまくいかなかったので、回避策をメモ。

検証環境
- Spring Boot 2.0.0

手順

依存関係の追加

POMにmicrometer-registry-prometheusの依存関係を追加します。これが公式リファレンスには記載がありませんでした。

pom.xml
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- この依存関係を追加するとうまくいった -->
<dependency>
  <groupId>io.micrometer</groupId>
  <artifactId>micrometer-registry-prometheus</artifactId>
</dependency>

エンドポイントの追加

application.propertiesでprometheusのエンドポイントを追加します。デフォルトではinfoとhealthのみ公開されています。

application.properties
# infoとhealthはデフォルトでexposeされているのでprometheusを追加
management.endpoints.web.exposure.include=info,health,prometheus

起動時のログ確認

起動すると以下のログが出力されます。/actuator/prometheusが出力されていればOKです。POMにmicrometer-registry-prometheusを追加しないとinfoとhealthしか出力されませんでした。

起動時ログ
Mapped "{[/actuator/health],methods=[GET],produces=[application/vnd.spring-boot.actuator.v2+json || application/json]}"
Mapped "{[/actuator/info],methods=[GET],produces=[application/vnd.spring-boot.actuator.v2+json || application/json]}"
Mapped "{[/actuator/prometheus],methods=[GET],produces=[text/plain;version=0.0.4;charset=utf-8]}"

以上です。

4
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
5