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

Managed Service for Prometheus:OpenTelemetry Collector を使用して Managed Service for Prometheus にメトリックを書き込む

最終更新日:Jun 23, 2026

Managed Service for Prometheus に、Container Service for Kubernetes (ACK) クラスターにデプロイされ、OpenTelemetry SDK でインストルメント化されたアプリケーションからメトリックを送信します。ネイティブの OpenTelemetry (OTel) メトリック、カスタムビジネスメトリック、およびトレーススパンから変換されたメトリックの収集を統合し、アプリケーションの完全な可観測性を実現します。トレースデータをメトリックに変換することで、データインジェスト量を大幅に削減できます。

OpenTelemetry の概要

OpenTelemetry (OTel) は、オープンソースの可観測性フレームワークであり、統合された API、SDK、およびツールを提供して、メトリックトレース、ログなどのテレメトリデータを分散システムから生成、収集、エクスポートします。その主な目的は、さまざまなツールやシステム間での可観測性データの断片化を解消することです。

OpenTelemetry のメトリックは、パフォーマンスと健全性のモニタリングのためにシステムの動作を定量化する構造化データです。メトリックのソースは、特定の言語向けの SDK またはエージェントのインストルメンテーションに依存します。Java アプリケーションの場合、メトリックには通常、標準の Java 仮想マシン (JVM) メトリック、ユーザーがインストルメント化したカスタムメトリック、およびトレースデータから派生したメトリックが含まれます。

OpenTelemetry のメトリックは、Prometheus と互換性があるように設計されています。OpenTelemetry Collector を使用すると、メトリックを Prometheus フォーマットに変換して、Managed Service for Prometheus とシームレスに統合できます。

OpenTelemetry Collector の役割

OpenTelemetry Collector は、アプリケーションやサービスからテレメトリデータを収集し、Prometheus などのターゲットシステムが必要とするフォーマットに変換する、拡張可能なデータ処理パイプラインです。

データ収集

アプリケーションは OpenTelemetry SDK を使用してメトリックデータを生成し、OpenTelemetry Protocol (OTLP) やネイティブの Prometheus プロトコルなどのプロトコルを使用して Collector に送信します。

データ変換

コミュニティの Collector 拡張機能は、OTel メトリックを Prometheus フォーマットに変換するための 2 つのエクスポーターを提供します。

  • Prometheus Exporter は、OpenTelemetry のメトリックを Prometheus フォーマットに変換し、Prometheus エージェントがデータをスクレイプするためのエンドポイントを提供します。

    1. メトリック名のマッピング:OpenTelemetry のメトリック名を Prometheus 互換のフォーマットに変換します。

    2. ラベル処理:Prometheus の命名規則に準拠するようにラベルを保持または名前変更します。

    3. データタイプの変換

      • gauge → Prometheus gauge

      • sum → Prometheus counter または gauge (Monotonic プロパティに基づく)

      • histogram → Prometheus histogram (bucket および sum サブメトリックを使用)

      次の構成例では、ポート 1234 でメトリックのスクレイピングエンドポイントを公開します。

      exporters:
        prometheus:
          endpoint: "0.0.0.0:1234"
          namespace: "acs"
          const_labels:
            label1: value1
          send_timestamps: true
          metric_expiration: 5m
          enable_open_metrics: true
          add_metric_suffixes: false
          resource_to_telemetry_conversion:
            enabled: true
  • Prometheus Remote Write Exporter は、OpenTelemetry のメトリックを Prometheus フォーマットに変換し、Remote Write プロトコルを使用してターゲットの Prometheus サービスに直接書き込みます。

    Prometheus Exporter と同様に、このエクスポーターもデータ形式を変換します。次のコードは構成例です。

    exporters:
      prometheusremotewrite:
        endpoint: http://<Prometheus Endpoint>/api/v1/write
        namespace: "acs"
        resource_to_telemetry_conversion:
          enabled: true
        timeout: 10s   
        headers:
          Prometheus-Remote-Write-Version: "0.1.0"
        external_labels:
          data-mode: metrics

ACK クラスターにおけるアプリケーションのベストプラクティス

ステップ 1:Managed Service for Prometheus の準備

  • クラスターで Prometheus モニタリングが有効になっている場合

    ご利用の ACK クラスターで Prometheus モニタリングが有効になっている場合、Prometheus インスタンスはすでに存在します。CloudMonitor コンソールにログインします。左側のナビゲーションウィンドウで、[Managed Service for Prometheus] > [インスタンス] を選択します。ご利用の ACK クラスターと同じ名前の Prometheus インスタンスを見つけ、指定されたリージョンでインスタンスが 実行中 の状態であることを確認します。

  • クラスターでは Prometheus モニタリングが有効になっていません。

    ACK コンソールにログインします。ターゲットクラスターの名前をクリックし、[アドオン] ページに移動します。[ロギングとモニタリング] タブで、ack-arms-prometheus コンポーネントを見つけてインストールします。インストール後、クラスターの Prometheus モニタリングが自動的に有効になります。コンポーネントがインストールされていることを確認します。

ステップ 2:サイドカーモードでの Collector のデプロイ

正確なメトリック計算のためには、単一の Pod からのすべてのメトリックとトレースを同じ Collector に送信する必要があります。ゲートウェイモードでのデプロイは複雑な負荷分散構成が必要となるため、サイドカーモードで Collector をデプロイすることを推奨します。

Prometheus Exporter モード

説明

この方法では、Prometheus の書き込みパスの認証が不要になります。また、スクレイピング構成を調整して、メトリック収集間隔を変更することもできます。

アーキテクチャ図
デプロイメント構成例
` を、ご利用のリージョンの ID に置き換えます。
          image: registry-<regionId>.ack.aliyuncs.com/acs/otel-collector:v0.128.0-7436f91	
          args: ["--config=/etc/otel/config/otel-config.yaml"]
          ports:
            - containerPort: 1234  # Prometheus エンドポイント
              name: metrics
          volumeMounts:
          - name: otel-config-volume
            mountPath: /etc/otel/config# Kubernetes Deployment の例
apiVersion: apps/v1
kind: Deployment
spec:
  template:
    metadata:
      labels:
        # Pod に特定のラベルを追加します。このラベルは通常、メトリックのスクレイプ設定を容易にするためにアプリケーション名にちなんで付けられます。
        observability: opentelemetry-collector
    spec:
      volumes:
      - name: otel-config-volume
        configMap:
          # この構成は、次の Collector 構成例に基づいて作成されます。
          name: otel-config
      containers:
        - name: app
          image: your-app:latest
          env:
            - name: OTEL_EXPORTER_OTLP_ENDPOINT
              value: http://localhost:4317
        - name: otel-collector
          # Alibaba Cloud が提供する Collector イメージを使用できます。このイメージには Prometheus 関連の拡張機能が含まれています。
          # イメージ名の <regionId> を、ご利用のリージョンの ID に置き換えてください。
          image: registry-<regionId>.ack.aliyuncs.com/acs/otel-collector:v0.128.0-7436f91	
          args: ["--config=/etc/otel/config/otel-config.yaml"]
          ports:
            - containerPort: 1234  # Prometheus エンドポイント
              name: metrics
          volumeMounts:
          - name: otel-config-volume
            mountPath: /etc/otel/config
Collector 構成例
説明

すべてのデータを処理できるように、アプリケーションのリクエスト量に基づいて Collector のリソース制限 (CPU とメモリ) を構成してください。

apiVersion: v1
kind: ConfigMap
metadata:
  name: otel-config
  namespace: <app-namespace>
data:
  otel-config.yaml: |
    extensions:
      zpages:
        endpoint: localhost:55679
    receivers:
      otlp:
        protocols:
          grpc:
            endpoint: 0.0.0.0:4317
          http:
            endpoint: 0.0.0.0:4318
    processors:
      batch:
      memory_limiter:
        # 最大メモリの 75% (最大 2 GB)
        limit_mib: 1536
        # 上限の 25% (最大 2 GB)
        spike_limit_mib: 512
        check_interval: 5s
      resource:
        attributes:
          - key: process.runtime.description
            action: delete
          - key: process.command_args
            action: delete
          - key: telemetry.distro.version
            action: delete
          - key: telemetry.sdk.name
            action: delete
          - key: telemetry.sdk.version
            action: delete
          - key: service.instance.id
            action: delete
          - key: process.runtime.name
            action: delete
          - key: process.runtime.description
            action: delete
          - key: process.pid
            action: delete
          - key: process.executable.path
            action: delete
          - key: process.command.args
            action: delete
          - key: os.description
            action: delete
          - key: instance
            action: delete
          - key: container.id
            action: delete
    connectors:
      spanmetrics:
        histogram:
          explicit:
            buckets: [0.001, 0.005, 0.01, 0.05, 0.1, 0.5, 1, 5, 10]
        dimensions: 
          - name: http.method
            default: "GET"
          - name: http.response.status_code
          - name: http.route
            # カスタム属性
          - name: user.id
        metrics_flush_interval: 15s
        exclude_dimensions:
        metrics_expiration: 3m
        events:
          enabled: true
          dimensions: 
          - name: default
            default: "GET"
    exporters:
      debug:
        verbosity: detailed
      prometheus:
        endpoint: "0.0.0.0:1234"
        namespace: "acs"
        const_labels:
          label1: value1
        send_timestamps: true
        metric_expiration: 5m
        enable_open_metrics: true
        add_metric_suffixes: false
        resource_to_telemetry_conversion:
          enabled: true
    service:
      pipelines:
        logs:
          receivers: [otlp]
          exporters: [debug]
        traces:
          receivers: [otlp]
          processors: [resource]
          exporters: [spanmetrics]
        metrics:
          receivers: [otlp]
          processors: [memory_limiter, batch]
          exporters: [prometheus]
        metrics/2:
          receivers: [spanmetrics]
          exporters: [prometheus]
      extensions: [zpages]

この構成は、受信したメトリックおよびトレースデータを処理します。resource タイプの processors を使用して、関連性のない環境属性を破棄し、メトリックデータ量を管理可能な範囲に保ちます。また、spanmetrics を使用して、主要なスパン統計をメトリックに変換します。

スクレイピングタスクの構成
apiVersion: monitoring.coreos.com/v1
kind: PodMonitor
metadata:
  name: opentelemetry-collector-podmonitor
  namespace: default
  annotations:
    arms.prometheus.io/discovery: "true"
spec:
  selector:
    matchLabels:
      observability: opentelemetry-collector
  podMetricsEndpoints:
  - port: metrics
    interval: 15s
    scheme: http
    path: /metrics

Prometheus Remote Write Exporter モード

説明
  • この方法は、データ量が多い、またはスクレイピングが不安定なシナリオに適しており、Collector が Prometheus インスタンスに直接書き込みます。

  • データ書き込みパスを構成する必要があるため、構成はより複雑になります。

アーキテクチャ図
データ書き込みパスの準備

このモードでは、Collector はデータを Prometheus インスタンスに直接書き込みます。続行する前に、Prometheus のエンドポイントと認証情報を取得してください。

  • エンドポイントの取得

    CloudMonitor コンソールにログインします。左側のナビゲーションウィンドウで、[Managed Service for Prometheus] > [インスタンス] を選択し、ご利用のクラスターに対応する Prometheus インスタンスを見つけます。Prometheus インスタンスの ID と名前は、通常、ACK クラスターの ID と名前と一致します。ターゲットインスタンスの名前をクリックします。[設定] ページで、Remote Write URL を見つけ、後で使用するために内部ネットワークアドレスをコピーします。

  • 認証情報の取得

    次のいずれかの方法を選択します。

    • V2 Prometheus インスタンスは、クラスターの VPC 内からのパスワードなしでの書き込みを許可する、パスワードなしのポリシーをサポートしています。

    • メトリックデータ書き込み用の RAM ユーザーを作成し、RAM ユーザーに AliyunPrometheusMetricWriteAccess システムポリシーを付与してから、その AccessKey ペアを取得します。AccessKey ID はユーザー名として、AccessKey Secret はデータ書き込みのパスワードとして使用されます。

デプロイメント構成例

Collector のデプロイメント構成は、Prometheus Exporter モードと同じです。詳細については、「Prometheus Exporter モードのデプロイメント構成例」をご参照ください。

Collector 構成例
apiVersion: v1
kind: ConfigMap
metadata:
  name: otel-config
  namespace: <app-namespace>
data:
  otel-config.yaml: |
    extensions:
    zpages:
      endpoint: localhost:55679
    receivers:
      otlp:
        protocols:
          grpc:
            endpoint: 0.0.0.0:4317
          http:
            endpoint: 0.0.0.0:4318
    processors:
      batch:
      memory_limiter:
        # 最大メモリの 75% (最大 2 GB)
        limit_mib: 1536
        # 上限の 25% (最大 2 GB)
        spike_limit_mib: 512
        check_interval: 5s
      resource:
        attributes:
          - key: process.runtime.description
            action: delete
          - key: process.command_args
            action: delete
          - key: telemetry.distro.version
            action: delete
          - key: telemetry.sdk.name
            action: delete
          - key: telemetry.sdk.version
            action: delete
          - key: service.instance.id
            action: delete
          - key: process.runtime.name
            action: delete
          - key: process.runtime.description
            action: delete
          - key: process.pid
            action: delete
          - key: process.executable.path
            action: delete
          - key: process.command.args
            action: delete
          - key: os.description
            action: delete
          - key: instance
            action: delete
          - key: container.id
            action: delete
    connectors:
      spanmetrics:
        histogram:
          explicit:
            buckets: [0.001, 0.005, 0.01, 0.05, 0.1, 0.5, 1, 5, 10]
        dimensions: 
          - name: http.method
            default: "GET"
          - name: http.response.status_code
          - name: http.route
            # カスタム属性
          - name: user.id
        metrics_flush_interval: 15s
        exclude_dimensions:
        metrics_expiration: 3m
        events:
          enabled: true
          dimensions: 
          - name: default
            default: "GET"
    exporters:
      debug:
        verbosity: detailed
      prometheusremotewrite:
        # これを Prometheus Remote Write エンドポイントの内部ネットワークアドレスに置き換えます。
        endpoint: http://<Endpoint>/api/v3/write
        namespace: "acs"
        resource_to_telemetry_conversion:
          enabled: true
        timeout: 10s   
        headers:
          Prometheus-Remote-Write-Version: "0.1.0"
          # このヘッダーは、パスワードなしのポリシーが有効になっていない場合に必要です。
          Authorization: Basic <base64-encoded-username-password>
        external_labels:
          data-mode: metrics
    service:
      pipelines:
        logs:
          receivers: [otlp]
          exporters: [debug]
        traces:
          receivers: [otlp]
          processors: [resource]
          exporters: [spanmetrics]
        metrics:
          receivers: [otlp]
          processors: [memory_limiter, batch]
          exporters: [prometheusremotewrite]
        metrics/2:
          receivers: [spanmetrics]
          exporters: [prometheusremotewrite]
      extensions: [zpages]
  • 構成内の Prometheus Remote Write エンドポイント URL を、取得した URL に置き換えます。

  • base64-encoded-username-password の値を生成するには、次のコマンドを実行します。

    echo -n 'AK:SK' | base64

ステップ 3:検証