Spring boot admin でAplicationのメトリックスを可視化

Spring boot adminはSpring bootで作られたアプリケーションの
管理者向けGUIツールです。
こんな風にSpring actuatorで提供されている情報を美しく表示したり
メモリの使用量等も見やすいですね。
https://raw.githubusercontent.com/codecentric/spring-boot-admin/master/screenshot-details.png

こんな風にアプリのログレベルをロガーごとにオンラインで変更できます。
https://raw.githubusercontent.com/codecentric/spring-boot-admin/master/screenshot-logging.png


導入方法は非常にシンプルです。
基本的には公式に書いてある通りにやればOKです。
https://github.com/codecentric/spring-boot-admin

構築にはeureka(service discovery)の仕組みを用いて
間接的にサーバーがクライアントを認識する方法と
クライアントから直接サーバーに存在を通知する方法の2通りあります。
今回は後者のクライアントから直接サーバーにクライアントの存在を通知する方法を取ります。
eurekaはまだ勉強中なので・・・

冗長構成の取り方等まだまだ調べることがありますが、運用支援ツールなので
今のところそこまで可用性を求めていません。
落ちていてもサービス維持に直結しませんから

サーバー

https://start.spring.io/ に行って適当にひな形プロジェクトを作りました。
pom.xmlにspring boot adminのserverとuiを追加します。

<dependency>
    <groupId>de.codecentric</groupId>
    <artifactId>spring-boot-admin-server</artifactId>
    <version>1.2.3</version>
</dependency>
<dependency>
    <groupId>de.codecentric</groupId>
    <artifactId>spring-boot-admin-server-ui</artifactId>
    <version>1.2.3</version>
</dependency>

@EnableAdminServerを追加してサーバー機能を有効化します。

@Configuration
@EnableAutoConfiguration
@EnableAdminServer //ここ重要
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

application.propertiesを作成して任意のポートを指定しておきます。
server.port=8888

クライアント

pom.xmlにclientの依存を追加

<dependency>
    <groupId>de.codecentric</groupId>
    <artifactId>spring-boot-admin-starter-client</artifactId>
    <version>1.2.3</version>
</dependency>

application.propertiesに先ほど立てたサーバーのサーバー名とPort番号を設定します。
spring.boot.admin.url=http://localhost:8888

私はspring actuatorのパス(management.context-path)を変更しているのですが、
Spring boot adminは特にそのパスを明示的に定義しなくても動作しました。