このソリューションは、Alibaba Cloud Managed Service for Prometheus を介して、OpenTelemetry SDK イベントトラッキングを使用して Container Service for Kubernetes (ACK) クラスタにデプロイされたアプリケーションの包括的なメトリックモニタリングを可能にします。 ネイティブの OTel メトリック、カスタムビジネス イベントトラッキング メトリック、およびトレーススパンから変換されたメトリックを統一的に収集できます。 トレースデータをメトリックに変換することで、データインジェスチョン量を効果的に削減できます。
OpenTelemetry の概要
OpenTelemetry (OTel) は、分散システムからテレメトリデータ (メトリック、トレース、ログを含む) を生成、収集、エクスポートするための統一された API、SDK、およびツールを提供するオープンソースの可観測性フレームワークです。 その中心的な目標は、さまざまなツールやシステム間での可観測性データの断片化の問題を解決することです。
OpenTelemetry メトリックは、システムの動作を定量化する構造化データであり、システムのパフォーマンスとヘルスステータスを監視するために使用されます。 メトリックソースは、さまざまな言語の SDK またはエージェント イベントトラッキング に依存します。 Java アプリケーションの場合、メトリックには通常、標準 JVM メトリック、カスタムメトリック、およびトレースデータから変換されたメトリックが含まれます。
OpenTelemetry のメトリック設計は Prometheus と互換性があります。 OpenTelemetry Collector を介して、メトリックを Prometheus 形式に変換できるため、Alibaba Cloud Managed Service for Prometheus とシームレスに統合できます。
OpenTelemetry Collector の役割
OpenTelemetry Collector は、データソース (アプリケーションやサービスなど) からテレメトリデータを収集し、データをターゲットシステム (Prometheus など) で必要な形式に変換する、拡張可能なデータ処理パイプラインです。
データ収集
アプリケーションは OpenTelemetry SDK を介してメトリックデータを生成し、OpenTelemetry Protocol (OTLP) または他のプロトコル (ネイティブ Prometheus プロトコルなど) を介して Collector に送信します。
データ変換
コミュニティ Collector 拡張機能では、次の 2 つのエクスポーターを使用して OTel メトリックを Prometheus 形式に変換できます。
Prometheus エクスポーター は、OpenTelemetry メトリックを Prometheus 形式に変換し、Prometheus エージェントがデータをスクレイプするためのエンドポイントを提供します。
メトリック名マッピング: OpenTelemetry メトリック名を Prometheus 互換形式に変換します。
ラベル処理: Prometheus の命名規則に準拠するようにラベルを保持または名前変更します。
データ型変換:
gauge→ Prometheusgaugesum→ Prometheuscounterまたはgauge(Monotonicプロパティに基づく)histogram→ Prometheushistogram(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 リモート書き込みエクスポーター は、OpenTelemetry メトリックを Prometheus 形式に変換し、RemoteWrite プロトコルを介してターゲット Prometheus サービスに直接書き込みます。
Prometheus エクスポーターと同様に、このエクスポーターもデータ形式変換を実行します。 設定例:
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 コンソール にログインし、 ページに移動して、ACK クラスタと同じ名前の Prometheus インスタンスを見つけます。

Prometheus モニタリングが有効になっていないクラスタ
ACK コンソール にログインし、クラスタ名をクリックして、[アドオン] ページに移動し、 ack-arms-prometheus コンポーネントをインストールします。これにより、クラスタの Prometheus モニタリングが自動的に有効になります。

2. Collector を SideCar モードでデプロイする
メトリックの統計計算では、同じポッドインスタンスからのメトリックまたはトレースが同じ Collector に到達する必要があるため、Gateway デプロイメントモードを使用するには、負荷分散を処理する必要があり、比較的複雑です。 そのため、Collector を SideCar モードでデプロイすることをお勧めします。
Prometheus エクスポーターモード
このアプローチの利点は、Prometheus 書き込みパスの認証を処理する必要がなく、収集構成を変更することでメトリック収集間隔を調整できることです。
デプロイメントアーキテクチャ図
デプロイメント構成リファレンス
# Kubernetes デプロイメント例
apiVersion: apps/v1
kind: Deployment
spec:
template:
metadata:
labels:
# ポッドに特定のラベルを追加します。通常は、メトリック収集構成を容易にするためにアプリケーション情報で名前が付けられます
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
# 提供されている 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/configCollector 構成リファレンス
アプリケーションのリクエスト量に応じて 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%、最大 2G
limit_mib: 1536
# 制限の 25%、最大 2G
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: /metricsPrometheus RemoteWrite エクスポーターモード
このアプローチは、データ量が大きく、収集が不安定なシナリオに適しており、Collector が Prometheus インスタンスに直接データを書き込みます。
構成は比較的複雑で、データ書き込みパスの構成を自分で処理する必要があります。
デプロイメントアーキテクチャ図
データ書き込みパスの準備
このメソッドでは、Collector が Prometheus インスタンスに直接データを書き込むため、最初に Prometheus エンドポイントと認証情報を取得する必要があります。
エンドポイントの取得
CloudMonitor コンソール にログインし、 ページに移動し、クラスタに対応する Prometheus インスタンスを見つけます。 ほとんどの場合、Prometheus インスタンス ID は ACK クラスタ ID と一致し、インスタンス名はコンテナクラスタ名と一致します。 インスタンス名をクリックします。 [設定] ページで、リモート書き込み URL を見つけ、後で使用する内部ネットワークアドレスを取得します。

認証情報の取得
次の 2 つのオプションがあります。
V2 Prometheus インスタンスは、パスワードなしポリシーの構成をサポートしており、クラスタの現在の VPC 内からのパスワードなし書き込みを許可します。
メトリックデータ書き込み用に Resource Access Management (RAM) ユーザーを割り当て、AliyunPrometheusMetricWriteAccess システムポリシーを割り当て、書き込みのユーザー名とパスワードとして使用する RAM ユーザーの AccessKey ペアを取得します。
デプロイメント構成リファレンス
Prometheus エクスポーターモード の Collector デプロイメント構成と同じです。
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%、最大 2G
limit_mib: 1536
# 制限の 25%、最大 2G
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 RemoteWrite 内部ネットワークアドレスに置き換えます
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 RemoteWrite エンドポイントを、前に取得したアドレスに置き換えます。
次のコマンドを実行して、
base64-encoded-username-passwordの値を取得します。echo -n 'AK:SK' | base64