すべてのプロダクト
Search
ドキュメントセンター

Container Service for Kubernetes:KServe に対する Prometheus モニタリングの設定:モデルサービスのパフォーマンスおよび健全性監視

最終更新日:Mar 26, 2026

KServe は、モデルサービスのパフォーマンスおよび健全性を監視するためのデフォルトの Prometheus メトリックを公開します。本トピックでは、scikit-learn を使用した InferenceService を Prometheus モニタリング有効化状態でデプロイし、推論トラフィックを生成して、ARMS で収集されたメトリックをクエリする手順について説明します。

前提条件

開始する前に、以下の条件を満たしていることを確認してください。

ステップ 1:KServe アプリケーションのデプロイ

  1. scikit-learn 向け KServe アプリケーションをデプロイします。

    リソースタイプ説明
    sklearn-iris-metric-svcKubernetes Serviceポート 8080 でメトリック エンドポイントを公開します
    sklearn-irisKServe InferenceServiceモデルサービング用リソースです
    sklearn-iris-svcmonitorServiceMonitorsklearn-iris-metric-svc
    arena serve kserve \
        --name=sklearn-iris \
        --image=kube-ai-registry.cn-shanghai.cr.aliyuncs.com/ai-sample/kserve-sklearn-server:v0.12.0 \
        --cpu=1 \
        --memory=200Mi \
        --enable-prometheus=true \
        --metrics-port=8080 \
        "python -m sklearnserver --model_name=sklearn-iris --model_dir=/models --http_port=8080"

    --enable-prometheus=true フラグにより、以下のリソースが作成されます。

    想定される出力:

    service/sklearn-iris-metric-svc created
    inferenceservice.serving.kserve.io/sklearn-iris created
    servicemonitor.monitoring.coreos.com/sklearn-iris-svcmonitor created
    INFO[0004] The Job sklearn-iris has been submitted successfully
    INFO[0004] You can run `arena serve get sklearn-iris --type kserve -n default` to check the job status
  2. 以下の内容で ./iris-input.json ファイルを作成します。このファイルは推論リクエストのペイロードとして使用されます。

    cat <<EOF > "./iris-input.json"
    {
      "instances": [
        [6.8,  2.8,  4.8,  1.4],
        [6.0,  3.4,  4.5,  1.6]
      ]
    }
    EOF
  3. NGINX Ingress ゲートウェイの IP アドレスおよび InferenceService のホスト名を取得します。

    NGINX_INGRESS_IP=`kubectl -n kube-system get svc nginx-ingress-lb -ojsonpath='{.status.loadBalancer.ingress[0].ip}'`
    SERVICE_HOSTNAME=$(kubectl get inferenceservice sklearn-iris -o jsonpath='{.status.url}' | cut -d "/" -f 3)
  4. Hey ストレステストツールを使用して推論トラフィックを生成します。

    hey -z 2m -c 20 -m POST -host $SERVICE_HOSTNAME -H "Content-Type: application/json" -D ./iris-input.json http://${NGINX_INGRESS_IP}:80/v1/models/sklearn-iris:predict

    想定される出力:

    クリックして想定される出力を表示

    Summary:
      Total:        120.0296 secs
      Slowest:      0.1608 secs
      Fastest:      0.0213 secs
      Average:      0.0275 secs
      Requests/sec: 727.3875
    
      Total data:   1833468 bytes
      Size/request: 21 bytes
    
    Response time histogram:
      0.021 [1]     |
      0.035 [85717] |■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
      0.049 [1272]  |■
      0.063 [144]   |
      0.077 [96]    |
      0.091 [44]    |
      0.105 [7]     |
      0.119 [0]     |
      0.133 [0]     |
      0.147 [11]    |
      0.161 [16]    |
    
    Latency distribution:
      10% in 0.0248 secs
      25% in 0.0257 secs
      50% in 0.0270 secs
      75% in 0.0285 secs
      90% in 0.0300 secs
      95% in 0.0315 secs
      99% in 0.0381 secs
    
    Details (average, fastest, slowest):
      DNS+dialup:  0.0000 secs, 0.0213 secs, 0.1608 secs
      DNS-lookup:  0.0000 secs, 0.0000 secs, 0.0000 secs
      req write:   0.0000 secs, 0.0000 secs, 0.0225 secs
      resp wait:   0.0273 secs, 0.0212 secs, 0.1607 secs
      resp read:   0.0001 secs, 0.0000 secs, 0.0558 secs
    
    Status code distribution:
      [200] 87308 responses
  5. (任意)ARMS でのクエリ実行前に、Pod からメトリックが正しく公開されているかを検証します。Pod はポート 8080 でメトリックを公開していますが、クラスター外部からはアクセスできません。ローカル環境でアクセスするには、ポート フォワーディングを使用します。

    メトリックタイプラベル説明
    request_preprocess_secondsヒストグラムmodel_name各リクエストの前処理遅延時間
    request_predict_secondsヒストグラムmodel_name各リクエストの予測遅延時間
    request_postprocess_secondsヒストグラムmodel_name各リクエストの後処理遅延時間
    request_explain_secondsヒストグラムmodel_name説明リクエストの遅延時間

    model_name ラベルにより、同一クラスター内で複数のモデルが実行されている場合でも、モデルごとにメトリックをフィルターおよび集計できます。

    # Pod 名を取得
    POD_NAME=`kubectl get po|grep sklearn-iris |awk -F ' ' '{print $1}'`
    # Pod のポート 8080 をローカルホストに転送
    kubectl port-forward pod/$POD_NAME 8080:8080

    想定される出力:

    クリックして想定される出力を表示

    # HELP python_gc_objects_collected_total Objects collected during gc
    # TYPE python_gc_objects_collected_total counter
    python_gc_objects_collected_total{generation="0"} 10298.0
    python_gc_objects_collected_total{generation="1"} 1826.0
    python_gc_objects_collected_total{generation="2"} 0.0
    # HELP python_gc_objects_uncollectable_total Uncollectable object found during GC
    # TYPE python_gc_objects_uncollectable_total counter
    python_gc_objects_uncollectable_total{generation="0"} 0.0
    python_gc_objects_uncollectable_total{generation="1"} 0.0
    python_gc_objects_uncollectable_total{generation="2"} 0.0
    # HELP python_gc_collections_total Number of times this generation was collected
    # TYPE python_gc_collections_total counter
    python_gc_collections_total{generation="0"} 660.0
    python_gc_collections_total{generation="1"} 60.0
    python_gc_collections_total{generation="2"} 5.0
    # HELP python_info Python platform information
    # TYPE python_info gauge
    python_info{implementation="CPython",major="3",minor="9",patchlevel="18",version="3.9.18"} 1.0
    # HELP process_virtual_memory_bytes Virtual memory size in bytes.
    # TYPE process_virtual_memory_bytes gauge
    process_virtual_memory_bytes 1.406291968e+09
    # HELP process_resident_memory_bytes Resident memory size in bytes.
    # TYPE process_resident_memory_bytes gauge
    process_resident_memory_bytes 2.73207296e+08
    # HELP process_start_time_seconds Start time of the process since unix epoch in seconds.
    # TYPE process_start_time_seconds gauge
    process_start_time_seconds 1.71533439115e+09
    # HELP process_cpu_seconds_total Total user and system CPU time spent in seconds.
    # TYPE process_cpu_seconds_total counter
    process_cpu_seconds_total 228.18
    # HELP process_open_fds Number of open file descriptors.
    # TYPE process_open_fds gauge
    process_open_fds 16.0
    # HELP process_max_fds Maximum number of open file descriptors.
    # TYPE process_max_fds gauge
    process_max_fds 1.048576e+06
    # HELP request_preprocess_seconds pre-process request latency
    # TYPE request_preprocess_seconds histogram
    request_preprocess_seconds_bucket{le="0.005",model_name="sklearn-iris"} 259709.0
    ...
    # HELP request_predict_seconds predict request latency
    # TYPE request_predict_seconds histogram
    request_predict_seconds_bucket{le="0.005",model_name="sklearn-iris"} 259708.0
    ...
    # HELP request_explain_seconds explain request latency
    # TYPE request_explain_seconds histogram
    Forwarding from 127.0.0.1:8080 -> 8080
    Forwarding from [::1]:8080 -> 8080

    ブラウザで http://localhost:8080/metrics を開き、生のメトリックを確認します。KServe は以下のメトリックを公開します。

ステップ 2:KServe アプリケーションのメトリックのクエリ

  1. ARMS コンソール にログインします。

  2. 左側ナビゲーションウィンドウで、統合管理 をクリックし、次に クエリダッシュボード をクリックします。

  3. ダッシュボード一覧 ページで、Kubernetes Pod ダッシュボードをクリックして Grafana ページを開きます。

  4. 左側ナビゲーションウィンドウで、Explore をクリックします。アプリケーションのメトリック値をクエリするには、以下の検索文を入力します。

    トラフィック生成後、データ収集には約 5 分の遅延があります。

    request_predict_seconds_bucket

    image

よくある質問

質問

request_predict_seconds_bucket のメトリックが正しく収集されているかを確認するにはどうすればよいですか?

ソリューション

ARMS におけるスクレイプ対象のステータスを確認します。

  1. ARMS コンソール にログインします。

  2. 左側ナビゲーションウィンドウで、統合管理 をクリックします。統合済み環境 ページで、Container Service タブをクリックし、ご利用のクラスター名をクリックします。その後、セルフモニタリング タブをクリックします。

  3. 左側ナビゲーションウィンドウで、Targets をクリックします。default/sklearn-iris-svcmonitor/0 (1/1 up) が一覧表示されていれば、メトリック収集は正常に動作しています。

参考文献