View a markdown version of this page

CloudWatch 指標 (OTel) - Amazon CloudWatch

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

CloudWatch 指標 (OTel)

選擇條件會決定哪些 OTel 指標進入管道進行處理。每個條件都是與傳入指標的特定屬性<path> == "<value>"相符的表單表達式。至少需要一個選擇條件。

條件會在具有 AND 語意的match_all區塊內分組 — 指標必須符合群組中的每個表達式,才能進入管道。

支援的路徑

選擇條件中支援下列 OTTL 路徑:

選擇條件路徑
路徑 說明

resource.attributes["key"]

資源層級屬性

instrumentation_scope.name

檢測範圍名稱

instrumentation_scope.version

檢測範圍版本

instrumentation_scope.attributes["key"]

檢測範圍屬性

metric.name

指標名稱

datapoint.attributes["key"]

Datapoint-level 屬性

attributes["key"]

的簡短格式 datapoint.attributes["key"]

組態

選擇條件在管道組態的 source區段中定義:

pipeline: source: cloudwatch_metrics: format: otlp selection_criteria: - match_all: - 'resource.attributes["service.name"] == "my-service"' - 'metric.name == "http.server.request.duration"' processor: - add_attributes: attributes: - key: resource.attributes["team"] value: "platform-engineering" sink: - cloudwatch_metrics: {}

下列範例使用所有支援的路徑類型:

pipeline: source: cloudwatch_metrics: format: otlp selection_criteria: - match_all: - 'resource.attributes["service.name"] == "my-service"' - 'instrumentation_scope.name == "my-scope"' - 'instrumentation_scope.version == "1.0.0"' - 'instrumentation_scope.attributes["library"] == "otel-java"' - 'metric.name == "http.server.request.duration"' - 'datapoint.attributes["status_code"] == "200"' - 'attributes["environment"] == "production"' processor: - add_attributes: attributes: - key: resource.attributes["team"] value: "observability" sink: - cloudwatch_metrics: {}

使用 PromQL 驗證

CloudWatch 使用@字首慣例將 OTLP 屬性範圍映射至 PromQL 標籤。使用此映射來驗證您的管道是否如預期在 Query Studio 中處理指標:

PromQL 標籤映射的 OTTL 路徑
管道 OTTL 路徑 PromQL 標籤字首 範例

resource.attributes["key"]

@resource.

@resource.service.name

instrumentation_scope.name

@instrumentation.@name

@instrumentation.@name

instrumentation_scope.attributes["key"]

@instrumentation.

@instrumentation.library

datapoint.attributes["key"] / attributes["key"]

@datapoint. 或裸機

status_code

例如,如果您的管道新增resource.attributes["team"]了 值 "platform-engineering",您可以確認已套用它:

{"CPUUtilization", "@resource.team"="platform-engineering"}

要求與限制

單一match_all群組

每個管道在 中僅支援一個match_all群組selection_criteria。您無法在單一管道中定義多個match_all群組。

最低條件

match_all 群組中至少需要一個表達式。

條件上限

match_all 群組最多可包含 20 個表達式。

AND 語意

match_all 群組中的所有表達式都必須相符,指標才能進入管道。

精確字串比對

值必須是靜態字串。不支援萬用字元、規則運算式和部分比對。每個表達式都必須使用 ==運算子。

管道之間沒有重疊的條件

每個指標資料點最多必須符合一個管道。如果資料點同時符合新的和現有的管道條件,則管道建立會失敗。為了防止重疊,請在每個管道的選擇條件中包含至少一個具有不同值的屬性路徑。

例如,以下兩個選擇條件重疊,因為管道 A 從 選取所有指標payment-service,其中包括管道 B 目標的特定指標:

# Pipeline A — selects ALL metrics from payment-service selection_criteria: - match_all: - 'resource.attributes["service.name"] == "payment-service"' # Pipeline B — FAILS: a datapoint with service.name="payment-service" # and metric.name="http.server.request.duration" matches both pipelines selection_criteria: - match_all: - 'metric.name == "http.server.request.duration"'