第2章 Quarkus アプリケーションでのメトリクスの公開
micrometer エクステンションを使用して Quarkus 1.11 でメトリクスを有効にします。有効にすると、micrometer エクステンションによって収集されるすべてのメトリクスのリアルタイム値は、/q/metrics エンドポイントを使用して表示されます。デフォルトでは、このエンドポイントはプレーンテキストでのみ応答します。
手順
quarkus-micrometer-registry-prometheusエクステンションを依存関係としてアプリケーションに追加します。./mvnw quarkus:add-extension -Dextensions="io.quarkus:quarkus-micrometer-registry-prometheus"
./mvnw quarkus:add-extension -Dextensions="io.quarkus:quarkus-micrometer-registry-prometheus"Copy to Clipboard Copied! Toggle word wrap Toggle overflow このコマンドにより、以下の依存関係が
pom.xmlに追加されます。pom.xml
<dependency> <groupId>io.quarkus</groupId> <artifactId>quarkus-micrometer-registry-prometheus</artifactId> </dependency><dependency> <groupId>io.quarkus</groupId> <artifactId>quarkus-micrometer-registry-prometheus</artifactId> </dependency>Copy to Clipboard Copied! Toggle word wrap Toggle overflow 以下のコマンドを入力して、ターミナルで収集したメトリクスを表示します。
curl http://localhost:8080/q/metrics
curl http://localhost:8080/q/metricsCopy to Clipboard Copied! Toggle word wrap Toggle overflow (オプション) Micrometer エクステンションを使用して JSON 形式でメトリクスのコレクションを有効にするには、以下の行を
src/main/resources/application.propertiesファイルに追加します。quarkus.micrometer.export.json.enabled=true
quarkus.micrometer.export.json.enabled=trueCopy to Clipboard Copied! Toggle word wrap Toggle overflow -
変更を
application.propertiesファイルに保存します。 以下のコマンドを使用して、JSON 形式でメトリクスを表示します。
curl -i -H "Accept: application/json" -H "Content-Type: application/json" http://localhost:8080/q/metrics
curl -i -H "Accept: application/json" -H "Content-Type: application/json" http://localhost:8080/q/metricsCopy to Clipboard Copied! Toggle word wrap Toggle overflow