プロセッサの一般的なユースケース
プロセッサの組み合わせに関する一般的なシナリオと設定例を次に示します。
例ログ形式を標準化し、メタデータを追加する
JSON ログを解析し、フィールド名を標準化して、環境情報を追加します。
processor: - parse_json: {} - rename_keys: entries: - from_key: "timestamp" to_key: "@timestamp" - from_key: "log_level" to_key: "level" - add_entries: entries: - key: "environment" value: "production" - key: "application" value: "payment-service"
例フィールド値をクリーンアップして正規化する
ステータスコードを標準化し、機密データを削除します。
processor: - uppercase_string: with_keys: ["status", "method"] - delete_entries: with_keys: ["credit_card", "password"] - substitute_string: entries: - source: "status" from: "SUCCESS" to: "OK"
例特定のフィールドを抽出および変換する
分析用のユーザー情報と形式を抽出します。
processor: - extract_value: entries: - source: "user_agent" target: "browser" from: "(?<browser>Chrome|Firefox|Safari)" to: "${browser}" - lowercase_string: with_keys: ["browser"] - move_keys: entries: - from_key: "browser" to_key: "user_data.browser"
例エントリレベルの条件を使用した条件付き処理
エントリレベルの when 条件を使用して、ログの重要度に基づいて異なるメタデータを追加します:
processor: - add_entries: entries: - key: "alert_level" value: "critical" when: "log.level == 'ERROR'" - key: "alert_level" value: "info" when_else: "log.level == 'ERROR'"
例不要なログエントリを削除する
サードパーティーのソースからデバッグとトレースのログエントリをフィルターで除外して、ノイズとストレージのコストを削減します。
processor: - drop_events: when: "log.level in {'DEBUG', 'TRACE'}" handle_expression_failure: "skip"
例 delete_entries を使用したプロセッサレベルの条件付き
環境が本番環境の場合にのみ、機密フィールドを削除します。
processor: - delete_entries: with_keys: ["password", "api_key", "ssn"] when: "environment in {'prod', 'staging'}"