字串操作處理器 - Amazon CloudWatch

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

字串操作處理器

字串處理器透過案例轉換、裁剪和模式比對等操作來修改日誌事件中的文字值。

lowercase_string 處理器

將指定欄位轉換為小寫。

Configuration

使用下列參數設定 lowercase_string 處理器:

processor: - lowercase_string: with_keys: ["status", "method"]
Parameters
with_keys (必要)

要轉換為小寫的欄位名稱陣列。僅處理字串值。

uppercase_string 處理器

將指定欄位轉換為大寫。

Configuration

使用下列參數設定 uppercase_string 處理器:

processor: - uppercase_string: with_keys: ["status_code", "method"]
Parameters
with_keys (必要)

要轉換為大寫的欄位名稱陣列。僅處理字串值。

trim_string 處理器

從指定的欄位移除前置和結尾空格。

Configuration

使用下列參數設定 trim_string 處理器:

processor: - trim_string: with_keys: ["message", "user_input"]
Parameters
with_keys (必要)

要修剪空格的欄位名稱陣列。僅處理字串值。

substitute_string 處理器

使用規則表達式執行字串替換。

Configuration

使用下列參數設定 substitute_string 處理器:

processor: - substitute_string: entries: - source: "message" from: "ERROR" to: "WARN"
Parameters
entries (必要)

在每個日誌事件上執行的替換操作陣列。

entries[].source (必要)

要在其中執行字串替換的欄位。

entries[].from (必要)

要比對和取代的規則表達式模式。

entries[].to (必要)

相符模式的取代字串。

截斷處理器

將欄位值截斷為指定的長度。

Configuration

使用下列參數設定截斷處理器:

processor: - truncate: source_keys: ["message", "description"] length: 100 start_at: 0
Parameters
source_keys (必要)

要截斷的欄位名稱陣列。每個欄位名稱最多 128 個字元。

length (選用)

截斷後的最大長度。範圍:1-8192。

start_at (選用)

截斷的起始位置。範圍:0-8192。預設為 0。

extract_value 處理器

使用規則表達式擷取值。

Configuration

使用下列參數設定 extract_value 處理器:

processor: - extract_value: entries: - source: "message" target: "extracted_data" from: "user=(?<user>\\w+)" to: "${user}" target_type: "string"
Parameters
entries (必要)

擷取操作的陣列。最多 20 個項目。

entries[].source (必要)

要擷取的欄位。最多 128 個字元。

entries[].target (必要)

擷取值的目標欄位。最多 128 個字元。

entries[].from (必要)

規則表達式模式。最多 128 個字元。

entries[].to (必要)

使用擷取群組取代模式。最多 128 個字元。

entries[].target_type (選用)

目標資料類型 (「整數」、「雙」、「字串」、「布林」)。

convert_entry_type 處理器

轉換不同資料類型之間的欄位值。

Configuration

使用下列參數設定 convert_entry_type 處理器:

processor: - convert_entry_type: key: "count" type: "integer"
Parameters
key (必要)

要轉換的單一欄位名稱。

type (必要)

目標資料類型。選項:"integer"、"double"、"string"、"boolean"。

日期處理器

剖析並格式化日期/時間欄位。

Configuration

使用下列參數設定日期處理器:

processor: - date: match: - key: "timestamp" patterns: ["yyyy-MM-dd'T'HH:mm:ss.SSSSSS'Z'"] destination: "@timestamp" source_timezone: "UTC" destination_timezone: "America/New_York"
Parameters
match (必要)

日期相符組態的陣列。最多 10 個項目。

match[].key (必要)

包含日期字串的欄位。最多 128 個字元。

match[].patterns (必要)

要嘗試的日期格式模式陣列。最多 5 個模式,每個模式最多 256 個字元。

destination (選用)

所有剖析日期的單一目標欄位。最多 128 個字元。

source_timezone (選用)

剖析的來源時區。

destination_timezone (選用)

輸出的目標時區。

output_format (選用)

輸出日期格式。最多 64 個字元。

destination_type (選用)

輸出類型 - "timestampz"、"long" 或 "string"。

剖析處理器

使用模式比對擷取結構化資料。

Configuration

使用下列參數設定剖析處理器:

processor: - dissect: map: message: "%{timestamp} %{level}"
Parameters
map (必要)

具有剖析模式的欄位映射。

list_to_map 處理器

將陣列欄位轉換為映射結構。

Configuration

使用下列參數設定 list_to_map 處理器:

processor: - list_to_map: source: "tags" key: "name" value_key: "value" target: "tag_map"
Parameters
source (必要)

包含陣列資料的欄位。最多 128 個字元。

key (必要)

用作映射索引鍵的欄位名稱。最多 128 個字元。

value_key (選用)

用作映射值的欄位名稱。最多 128 個字元。

target (選用)

映射結構的目標欄位。最多 128 個字元。

flatten (選用)

是否平面化產生的映射。

flattened_element (選用)

平面化時要使用的元素 (「第一個」或「最後一個」)。

rename_keys 處理器

重新命名日誌事件中的欄位。

Configuration

使用下列參數設定 rename_keys 處理器:

processor: - rename_keys: entries: - from_key: "old_name" to_key: "new_name" overwrite_if_to_key_exists: true
Parameters
entries (必要)

重新命名操作的陣列。最多 5 個項目。

entries[].from_key (必要)

目前欄位名稱。最多 128 個字元。

entries[].to_key (必要)

新的欄位名稱。最多 128 個字元。

entries[].overwrite_if_to_key_exists (選用)

是否覆寫現有的目標欄位。

select_entries 處理器

僅從事件中選取指定的欄位。

Configuration

使用下列參數設定 select_entries 處理器:

processor: - select_entries: include_keys: ["timestamp", "level", "message"]
Parameters
include_keys (必要)

要保留的欄位名稱陣列。最多 50 個金鑰,每個最多 128 個字元。

轉譯處理器

使用查詢資料表翻譯欄位值。

Configuration

使用下列參數設定轉譯處理器:

processor: - translate: mappings: - source: "status_code" targets: - target: "status_text" map: "200": "OK" "404": "Not Found"
Parameters
mappings (必要)

轉譯組態陣列。最多 10 個映射。

mappings[].source (必要)

要翻譯的欄位。最多 128 個字元。

mappings[].targets (必要)

目標組態陣列。最多 10 個目標。

mappings[].targets[].target (必要)

目標欄位名稱。最多 128 個字元。

mappings[].targets[].map (必要)

轉譯映射。最多 100 個項目,每個值最多 512 個字元。