> ## Documentation Index
> Fetch the complete documentation index at: https://docs.abbyy.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Prometheus を使用した Monitoring

> Istio と Linkerd のサービスメッシュ全体で、Prometheus を使用して Vantage 3.0 セルフホスト型のメトリクスを収集します。

このガイドでは、あらゆる環境で Vantage 3.0 セルフホスト型のメトリクスを収集するために、セルフマネージドの Prometheus を設定します。AKS で Azure Monitor Workspace と Azure Managed Grafana を利用できる場合は、同じパターンをマネージドサービスとしてデプロイする方法について、[Azure Managed Monitoring](/ja/vantage/self-hosted/v3.0/monitoring/azure-managed) を参照してください。

<Note>
  例では [kube-prometheus-stack](https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-prometheus-stack) を使用していますが、アプローチ自体は汎用的で、どの Prometheus デプロイにも適用できます。メッシュ固有の制約については、[監視の概要](/ja/vantage/self-hosted/v3.0/monitoring/overview) を参照してください。
</Note>

<div id="how-vantage-exposes-metrics">
  ## Vantage でのメトリクス公開方法
</div>

Vantage アプリケーションの pod には OpenTelemetry SDK が組み込まれており、コンテナーポート 8080 の `/metrics-text` で Prometheus 形式のメトリクスを公開します。このエンドポイントを公開するサービスには `abbyy.platform.metrics.text.endpoint: "1"` というラベルが付いており、サービスポート (通常は 80) が、ポート名 `http` のコンテナーポートにマップされます。Prometheus は `ServiceMonitor` を介してこれらのサービスを検出し、スクレイプします。そのため、メトリクス収集用に別途 OpenTelemetry Collector を用意する必要はありません。

全体像とサービスメッシュの制約については、[監視の概要](/ja/vantage/self-hosted/v3.0/monitoring/overview)を参照してください。

<div id="prerequisites">
  ## 前提条件
</div>

* Vantage がインストールされ、稼働中であること (operator とワークロードがデプロイ済み) 。
* Helm 3。
* クラスターに対する `kubectl` アクセス。
* KEDA が有効な場合は、`prometheus-operated.observability.svc.cluster.local:9090` でアクセス可能な Prometheus インスタンス。

<div id="configure-prometheus">
  ## Prometheus を設定する
</div>

OTLP メトリクスを取り込む場合は、`otlp-write-receiver` 機能を有効にし、Prometheus インスタンスに `--web.enable-otlp-receiver` 引数を渡します ([OTLP取り込み](#otlp-ingestion)を参照) 。

Helm リポジトリを追加します:

```bash theme={null}
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
```

`values` ファイル (`observability-values.yaml`) を作成します：

```yaml theme={null}
prometheus:
  prometheusSpec:
    enableFeatures:
      - otlp-write-receiver
    additionalArgs:
      - name: web.enable-otlp-receiver
        value: ""
    retention: 15d
    storageSpec:
      volumeClaimTemplate:
        spec:
          accessModes: ["ReadWriteOnce"]
          resources:
            requests:
              storage: 50Gi
    resources:
      requests:
        cpu: 500m
        memory: 2Gi
      limits:
        cpu: "2"
        memory: 4Gi
grafana:
  enabled: true
  adminPassword: "changeme"  # 本番環境では必ず変更してください
  persistence:
    enabled: true
    size: 10Gi
alertmanager:
  enabled: false
nodeExporter:
  enabled: true
kube-state-metrics:
  enabled: true
# マネージドKubernetes（AKS、EKS、GKEなど）はコントロールプレーンの
# エンドポイントを公開しません。スクレイプエラーを防ぐため、これらを無効にしてください。
kubeApiServer:
  enabled: false
kubeControllerManager:
  enabled: false
kubeScheduler:
  enabled: false
kubeEtcd:
  enabled: false
kubeProxy:
  enabled: false
```

インストール:

```bash theme={null}
helm install observability prometheus-community/kube-prometheus-stack \
  -n observability --create-namespace \
  -f observability-values.yaml
```

pod が起動していることを確認します:

```bash theme={null}
kubectl get pods -n observability
```

Prometheus、Grafana、operator、kube-state-metrics、node-exporter の各 pod が実行中であることを確認してください。node-exporter は DaemonSet として実行されるため、ノードのスケーリングがまだ進行中の場合は、保留中の pod があっても正常です。

<div id="configure-prometheus-to-scrape-vantage">
  ## Prometheus が Vantage をスクレイプするように設定する
</div>

`vantage-selfhosted` チャートでは、Vantage を監視するために必要な `ServiceMonitor` オブジェクトを作成できます。

```bash theme={null}
helm upgrade --install abbyy-vantage \
  # ...
  --set observability.prometheus.serviceMonitor.create=true
```

その他のオプションについては、チャートのDocumentationを参照してください。

`observability` キーはトップレベルに配置する必要があり、`vantage` の下にネストしてはいけません。

<div id="linkerd-mtls">
  ## Linkerd mTLS
</div>

Linkerd の既定の permissive ポリシーでは、Prometheus は通常、Linkerd でプロキシされた Vantage エンドポイントをプレーンテキスト経由でスクレイプできます。Prometheus を `observability` 名前空間にインストールし、Vantage の `ServiceMonitor` を有効にして、すべての Vantage ターゲットが `UP` であることを確認してください。

厳格な Linkerd 認可ポリシーによってスクレイプがブロックされる場合は、次のいずれかの方法を使用してください。

1. `observability` 名前空間で Linkerd インジェクションを有効にし、Prometheus がメッシュに参加するようにします。
2. `observability.prometheus.serviceMonitor.scheme: https` と、Linkerd の構成によって Prometheus で利用可能になるクライアント証明書を参照する `tlsConfig` を設定します。

`ScaledObject` リソースで使用される Vantage メトリクスについて、Prometheus が最新の値を返すようになるまで、KEDA を有効にしないでください。確認用クエリと準備完了チェックについては、[KEDA による自動スケーリング](/ja/vantage/self-hosted/v3.0/performance/autoscaling)を参照してください。

<div id="istio-mtls">
  ## Istio mTLS
</div>

Vantage を STRICT mTLS を使用する Istio メッシュに配置する場合 (`ingress.enabled` が `true` で `ingress.type` が `istio` の場合のデフォルト設定) 、Prometheus は service 名ではなく pod IP を直接使用するため、Prometheus と \`ServiceMonitor\`\` は mTLS 経由でエンドポイントをスクレイプするように設定する必要があります。

Prometheus pod に次のアノテーションを設定します。

```yaml theme={null}
annotations:
  proxy.istio.io/config: |
    proxyMetadata:
      OUTPUT_CERTS: /etc/istio-output-certs
  sidecar.istio.io/userVolumeMount: '[{"name": "istio-certs", "mountPath": "/etc/istio-output-certs"}]'
```

および、次の `volume` と `volumeMount` (名前とパスはカスタマイズ可能です。以下の例ではこれらを使用しています) :

```yaml theme={null}
volumes:
  - name: istio-certs
    emptyDir:
      medium: Memory
volumeMounts:
  - name: istio-certs
    mountPath: /etc/prom-certs/
    readOnly: true
```

kube-prometheus-stack では、次の値を使用してこれを行えます。

```yaml theme={null}
prometheus:
  prometheusSpec:
    podMetadata:
      annotations:
        # Istio にローカルボリュームディレクトリへの証明書生成を強制する
        "proxy.istio.io/config": |
          proxyMetadata:
            OUTPUT_CERTS: /etc/istio-output-certs
        "sidecar.istio.io/userVolumeMount": '[{"name": "istio-certs", "mountPath": "/etc/istio-output-certs"}]'
    # Istio が証明書を書き込む共有ボリューム
    volumes:
      - name: istio-certs
        emptyDir: {}
    volumeMounts:
      - name: istio-certs
        mountPath: /etc/prom-certs
```

または、[Istio の公式ドキュメント](https://istio.io/latest/docs/ops/integrations/prometheus/#tls-settings)を参照してください。

次に、`ServiceMonitor`(s) がこれらの証明書を使用するよう設定されるように、`vantage-selfhosted` チャートをインストールします。

```yaml theme={null}
# values.vantage-selfhosted.yaml
observability:
  prometheus:
    serviceMonitor:
      scheme: https
      tlsConfig:
        caFile: /etc/prom-certs/root-cert.pem
        certFile: /etc/prom-certs/cert-chain.pem
        keyFile: /etc/prom-certs/key.pem
        insecureSkipVerify: true  # PrometheusはIstioのセキュリティ命名をサポートしていないため、ターゲットpodの証明書の検証をスキップする
```

<div id="verify-metrics-are-flowing">
  ## メトリクスが送信されていることを確認する
</div>

Prometheus UI にポートフォワードします:

```bash theme={null}
kubectl port-forward -n observability svc/observability-kube-prometheus-prometheus 9090:9090
```

Vantage のターゲットが検出され、正常に稼働していることを確認します:

```bash theme={null}
curl -s http://localhost:9090/api/v1/targets \
  | jq '[.data.activeTargets[] | select(.scrapePool // "" | contains("vantage"))] | group_by(.health) | map({health: .[0].health, count: length})'
```

Vantage アプリケーションのメトリックを照会します:

```bash theme={null}
curl -s "http://localhost:9090/api/v1/query?query=process_cpu_count" \
  | jq '.data.result | length'
```

結果が 0 以外であれば、メトリクスがスクレイプされていることを示します。`http://localhost:9090/targets` にアクセスすると、各ターゲットのスクレイプ ステータスも確認できます。

<div id="access-grafana">
  ## Grafana にアクセスする
</div>

```bash theme={null}
kubectl port-forward -n observability svc/observability-grafana 3000:80
```

`http://localhost:3000` を開きます。デフォルトの認証情報は、`admin` と values ファイルで設定したパスワードです。Prometheus はデータソースとして事前に設定されています。

<div id="available-metrics">
  ## 利用可能なメトリクス
</div>

Vantage アプリケーションは、OpenTelemetry SDK を介して、プロセス、HTTP クライアント/サーバー、および ABBYY プラットフォームのメトリクスを公開します。これらにはすべて、`service`、`pod`、`namespace`、`otel_scope_name` のラベルが付与されています。全メトリクスの一覧については、[利用可能なメトリクス](/ja/vantage/self-hosted/v3.0/monitoring/overview#available-metrics) を参照してください。

<div id="otlp-ingestion">
  ## OTLP取り込み
</div>

<Note>
  OTLP取り込みはプッシュベースで、上記のスクレイプベースの `ServiceMonitor` フローとは独立しています。スクレイプエンドポイントを公開するサービスではなく、OpenTelemetry メトリクスをプッシュするサービスにのみ使用してください。
</Note>

Prometheus で OTLP レシーバーを有効にして構成している場合 (`--web.enable-otlp-receiver`) 、HTTP 経由で OTLP メトリクスをプッシュするサービスであれば、どれでもそれらを次の宛先に送信できます。

```text theme={null}
http://observability-kube-prometheus-prometheus.observability:9090/api/v1/otlp/v1/metrics
```
