Spring-boot-actuator

提供:Dev Guides
移動先:案内検索

スプリングブート-アクチュエータ

Spring Boot Actuatorは、Spring Bootアプリケーションを監視および管理するための安全なエンドポイントを提供します。 デフォルトでは、すべてのアクチュエータエンドポイントが保護されています。 この章では、アプリケーションに対してSpring Bootアクチュエータを有効にする方法について詳しく学習します。

Spring Bootアクチュエータを有効にする

Spring BootアプリケーションのSpring Bootアクチュエータエンドポイントを有効にするには、ビルド構成ファイルにSpring Boot Starterアクチュエータの依存関係を追加する必要があります。

Mavenユーザーは、pom.xmlファイルに以下の依存関係を追加できます。

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

Gradleユーザーは、build.gradleファイルに以下の依存関係を追加できます。

compile group: 'org.springframework.boot', name: 'spring-boot-starter-actuator'

application.propertiesファイルで、アクチュエータエンドポイントのセキュリティを無効にする必要があります。

management.security.enabled = false

YAMLファイルユーザーは、application.ymlファイルに次のプロパティを追加できます。

management:
   security:
      enabled: false

Springブートアクチュエータエンドポイントへのアクセスに別のポート番号を使用する場合は、application.propertiesファイルに管理ポート番号を追加します。

management.port = 9000

YAMLファイルユーザーは、application.ymlファイルに次のプロパティを追加できます。

management:
   port: 9000

これで、次のMavenまたはGradleコマンドを使用して、実行可能JARファイルを作成し、Spring Bootアプリケーションを実行できます。

Mavenの場合、次のコマンドを使用できます-

mvn clean install

「BUILD SUCCESS」の後、ターゲットディレクトリの下にJARファイルがあります。

Gradleの場合、次のコマンドを使用できます-

gradle clean build

「BUILD SUCCESSFUL」の後、build/libsディレクトリの下にJARファイルがあります。

これで、次のコマンドを使用してJARファイルを実行できます-

java –jar <JARFILE>

これで、アプリケーションはTomcatポート8080で開始されました。 管理ポート番号を指定した場合、同じアプリケーションが2つの異なるポート番号で実行されていることに注意してください。

TomcatポートのStartedcアプリケーション

いくつかの重要なSpring Boot Actuatorエンドポイントを以下に示します。 Webブラウザに入力して、アプリケーションの動作を監視できます。

ENDPOINTS USAGE
/metrics To view the application metrics such as memory used, memory free, threads, classes, system uptime etc.
/env To view the list of Environment variables used in the application.
/beans To view the Spring beans and its types, scopes and dependency.
/health To view the application health
/info To view the information about the Spring Boot application.
/trace To view the list of Traces of your Rest endpoints.