メトリクスによる洞察の獲得

Keycloak の実行中のインスタンスの状態とアクティビティに関する洞察を得るために、メトリクスを収集します。

Keycloak にはメトリクスの組み込みサポートがあります。このガイドでは、サーバーメトリクスを有効にして構成する方法について説明します。

メトリクスの有効化

メトリクスは、ビルド時のオプション metrics-enabled を使用して有効にできます。

bin/kc.[sh|bat] start --metrics-enabled=true

メトリクスのクエリ

Keycloak は、管理インターフェース上の次のエンドポイントでメトリクスを公開します。

  • /metrics

管理インターフェースの詳細については、管理インターフェースの設定 を参照してください。エンドポイントからのレスポンスは、application/openmetrics-text コンテンツタイプを使用し、Prometheus(OpenMetrics)テキスト形式に基づいています。以下のスニペットは、レスポンスの例です。

# HELP base_gc_total Displays the total number of collections that have occurred. This attribute lists -1 if the collection count is undefined for this collector.
# TYPE base_gc_total counter
base_gc_total{name="G1 Young Generation",} 14.0
# HELP jvm_memory_usage_after_gc_percent The percentage of long-lived heap pool used after the last GC event, in the range [0..1]
# TYPE jvm_memory_usage_after_gc_percent gauge
jvm_memory_usage_after_gc_percent{area="heap",pool="long-lived",} 0.0
# HELP jvm_threads_peak_threads The peak live thread count since the Java virtual machine started or peak was reset
# TYPE jvm_threads_peak_threads gauge
jvm_threads_peak_threads 113.0
# HELP agroal_active_count Number of active connections. These connections are in use and not available to be acquired.
# TYPE agroal_active_count gauge
agroal_active_count{datasource="default",} 0.0
# HELP base_memory_maxHeap_bytes Displays the maximum amount of memory, in bytes, that can be used for memory management.
# TYPE base_memory_maxHeap_bytes gauge
base_memory_maxHeap_bytes 1.6781410304E10
# HELP process_start_time_seconds Start time of the process since unix epoch.
# TYPE process_start_time_seconds gauge
process_start_time_seconds 1.675188449054E9
# HELP system_load_average_1m The sum of the number of runnable entities queued to available processors and the number of runnable entities running on the available processors averaged over a period of time
# TYPE system_load_average_1m gauge
system_load_average_1m 4.005859375

...

次のステップ

メトリクスの使用方法については、サービスレベルインジケーターによるパフォーマンスの監視 および メトリクスを使用したトラブルシューティング のガイドをお読みください。

関連オプション

cache-metrics-histograms-enabled

埋め込みキャッシュのメトリクスのヒストグラムを有効にします。

CLI: --cache-metrics-histograms-enabled
Env: KC_CACHE_METRICS_HISTOGRAMS_ENABLED

メトリクスが有効になっている場合にのみ使用可能

true, false (デフォルト)

http-metrics-histograms-enabled

HTTP サーバーリクエストの期間に対するデフォルトのバケットを持つヒストグラムを有効にします。

CLI: --http-metrics-histograms-enabled
Env: KC_HTTP_METRICS_HISTOGRAMS_ENABLED

メトリクスが有効になっている場合にのみ使用可能

true, false (デフォルト)

http-metrics-slos

HTTP サーバーリクエストのサービスレベル目標。

デフォルトのヒストグラムの代わりに使用するか、組み合わせて追加のバケットを追加します。ミリ秒単位で定義されたコンマ区切りの値のリストを指定します。5ms から 10s までのバケットの例:5,10,25,50,250,500,1000,2500,5000,10000

CLI: --http-metrics-slos
Env: KC_HTTP_METRICS_SLOS

メトリクスが有効になっている場合にのみ使用可能

metrics-enabled

サーバーがメトリクスを公開する必要があるかどうか。

有効にすると、メトリクスは /metrics エンドポイントで利用可能になります。

CLI: --metrics-enabled
Env: KC_METRICS_ENABLED

true, false (デフォルト)

このページについて