ホスト Agent ログの収集

ログの収集には、Datadog Agent v6.0 以上が必要です。古いバージョンの Agent には、log collection インターフェイスが含まれていません。まだ Agent を使用していない場合は、Agent のインストール手順に従ってください。

他のベンダーのコレクターやフォワーダーを使用してログを送信したい場合、または配信前に環境内でログデータを前処理したい場合は、Observability Pipelines を参照してください。

ログ収集を有効にする

Datadog Agent では、ログの収集はデフォルトで有効になっていません。Agent を Kubernetes または Docker 環境で実行している場合は、専用の Kubernetes ログ収集または Docker ログ収集のドキュメントを参照してください。

ホストで実行されている Agent でログ収集を有効にするには、Agent のメインコンフィギュレーションファイル (datadog.yaml) で logs_enabled: falselogs_enabled: true に変更します。

datadog.yaml

## @param logs_enabled - boolean - optional - default: false
## @env DD_LOGS_ENABLED - boolean - optional - default: false
## Enable Datadog Agent log collection by setting logs_enabled to true.
logs_enabled: false

## @param logs_config - custom object - optional
## Enter specific configurations for your Log collection.
## Uncomment this parameter and the one below to enable them.
## See https://docs.datadoghq.com/agent/logs/
logs_config:

  @param container_collect_all - boolean - optional - default: false
  @env DD_LOGS_CONFIG_CONTAINER_COLLECT_ALL - boolean - optional - default: false
  Enable container log collection for all the containers (see ac_exclude to filter out containers)
  container_collect_all: false

  @param logs_dd_url - string - optional
  @env DD_LOGS_CONFIG_LOGS_DD_URL - string - optional
  Define the endpoint and port to hit when using a proxy for logs.
  As of agent version 7.70.0, proxy paths are supported. To forward logs to a
  specific proxy path, the URL scheme must be specified: https://proxy.example.com:443/logs
  logs_dd_url: <ENDPOINT>:<PORT>

  @param logs_no_ssl - boolean - optional - default: false
  @env DD_LOGS_CONFIG_LOGS_NO_SSL - optional - default: false
  Disable the SSL encryption. This parameter should only be used when logs are
  forwarded locally to a proxy. It is highly recommended to then handle the SSL encryption
  on the proxy side.
  logs_no_ssl: false

  @param processing_rules - list of custom objects - optional
  @env DD_LOGS_CONFIG_PROCESSING_RULES - list of custom objects - optional
  Global processing rules that are applied to all logs. The available rules are
  "exclude_at_match", "include_at_match" and "mask_sequences". More information in Datadog documentation:
  https://docs.datadoghq.com/agent/logs/advanced_log_collection/#global-processing-rules
  processing_rules:
    - type: <RULE_TYPE>
      name: <RULE_NAME>
      pattern: <RULE_PATTERN>

  @param auto_multi_line_detection - boolean - optional - default: false
  @env DD_LOGS_CONFIG_AUTO_MULTI_LINE_DETECTION - boolean - optional - default: false
  Enable automatic aggregation of multi-line logs for common log patterns.
  More information can be found in Datadog documentation:
  https://docs.datadoghq.com/agent/logs/auto_multiline_detection/?tab=configurationfile
  auto_multi_line_detection: true

  @param force_use_http - boolean - optional - default: false
  @env DD_LOGS_CONFIG_FORCE_USE_HTTP - boolean - optional - default: false
  Set this parameter to `true` to always send logs via HTTP(S) protocol and never fall back to
  raw TCP forwarding (recommended).
  #
  By default, the Agent sends logs in HTTPS batches if HTTPS connectivity can
  be established at Agent startup, and falls back to TCP otherwise. This parameter
  can be used to override this fallback behavior. It is recommended, but not the default, to
  maintain compatibility with previous Agent versions.
  #
  Note, the logs are forwarded via HTTPS (encrypted) by default. Please use `logs_no_ssl` if you
  need unencrypted HTTP instead.
  force_use_http: true

  @param http_protocol - string - optional - default: auto
  @env DD_LOGS_CONFIG_HTTP_PROTOCOL - string - optional - default: auto
  The transport type to use for sending logs. Possible values are "auto" or "http1".
  http_protocol: auto

  @param http_timeout - integer - optional - default: 10
  @env DD_LOGS_CONFIG_HTTP_TIMEOUT - integer - optional - default: 10
  The HTTP timeout to use for sending logs, in seconds.
  http_timeout: 10

  @param force_use_tcp - boolean - optional - default: false
  @env DD_LOGS_CONFIG_FORCE_USE_TCP - boolean - optional - default: false
  By default, logs are sent via HTTP protocol if possible, set this parameter
  to `true` to always send logs via TCP. If `force_use_http` is set to `true`, this parameter
  is ignored.
  force_use_tcp: true

  @param use_compression - boolean - optional - default: true
  @env DD_LOGS_CONFIG_USE_COMPRESSION - boolean - optional - default: true
  This parameter is available when sending logs via HTTP protocol. If enabled, the Agent
  compresses logs before sending them.
  use_compression: true

  @param compression_level - integer - optional - default: 6
  @env DD_LOGS_CONFIG_COMPRESSION_LEVEL - boolean - optional - default: false
  The compression_level parameter accepts values from 0 (no compression)
  to 9 (maximum compression but higher resource usage). Only takes effect if
  `use_compression` is set to `true`.
  compression_level: 6

  @param batch_wait - integer - optional - default: 5
  @env DD_LOGS_CONFIG_BATCH_WAIT - integer - optional - default: 5
  The maximum time (in seconds) the Datadog Agent waits to fill each batch of logs before sending.
  batch_wait: 5

  @param close_timeout - integer - optional - default: 60
  @env DD_LOGS_CONFIG_CLOSE_TIMEOUT - integer - optional - default: 60
  The maximum number of seconds the Agent spends reading from a file after it has been rotated.
  close_timeout: 60

  @param open_files_limit - integer - optional - default: 500
  @env DD_LOGS_CONFIG_OPEN_FILES_LIMIT - integer - optional - default: 500
  The maximum number of files that can be tailed in parallel.
  Note: the default for Mac OS is 200. The default for
  all other systems is 500.
  open_files_limit: 500

  @param file_wildcard_selection_mode - string - optional - default: `by_name`
  @env DD_LOGS_CONFIG_FILE_WILDCARD_SELECTION_MODE - string - optional - default: `by_name`
  The strategy used to prioritize wildcard matches if they exceed the open file limit.
  #
  Choices are `by_name` and `by_modification_time`.
  #
  `by_name` means that each log source is considered and the matching files are ordered
  in reverse name order. While there are less than `logs_config.open_files_limit` files
  being tailed, this process repeats, collecting from each configured source.
  #
  `by_modification_time` takes all log sources and first adds any log sources that
  point to a specific file. Next, it finds matches for all wildcard sources.
  This resulting list is ordered by which files have been most recently modified
  and the top `logs_config.open_files_limit` most recently modified files are
  chosen for tailing.
  #
  WARNING: `by_modification_time` is less performant than `by_name` and will trigger
  more disk I/O at the configured wildcard log paths.
  file_wildcard_selection_mode: by_name

  @param max_message_size_bytes - integer - optional - default: 900000
  @env DD_LOGS_CONFIG_MAX_MESSAGE_SIZE_BYTES - integer - optional - default : 900000
  The maximum size of single log message in bytes. If maxMessageSizeBytes exceeds
  the documented API limit of 1MB - any payloads larger than 1MB will be dropped by the intake.
  https://docs.datadoghq.com/api/latest/logs/
  max_message_size_bytes: 900000

  @param integrations_logs_files_max_size - integer - optional - default: 10
  @env DD_LOGS_CONFIG_INTEGRATIONS_LOGS_FILES_MAX_SIZE - integer - optional - default: 10
  The max size in MB that an integration logs file is allowed to use
  integrations_logs_files_max_size: 10

  @param integrations_logs_total_usage - integer - optional - default: 100
  @env DD_LOGS_CONFIG_INTEGRATIONS_LOGS_TOTAL_USAGE - integer - optional - default: 100
  The total combined usage all integrations logs files can use
  integrations_logs_total_usage: 100

  @param kublet_api_client_read_timeout - duration - optional - default: 30s
  @env DD_LOGS_CONFIG_KUBELET_API_CLIENT_READ_TIMEOUT - duration - optional - default: 30s
  Configure the kubelet API client's timeout used while streaming logs.
  kublet_api_client_read_timeout: 30

  @param k8s_container_use_kubelet_api - boolean - optional - default: false
  @env DD_LOGS_CONFIG_K8S_CONTAINER_USE_KUBELET_API - boolean - optional - default: false
  Enable container log collection via the kubelet API, typically used for EKS Fargate
  k8s_container_use_kubelet_api: false

  @param streaming - custom object - optional
  This section allows you to configure streaming logs via remote config.
  streaming:
    @param streamlogs_log_file - string - optional
    @env DD_LOGS_CONFIG_STREAMING_STREAMLOGS_LOG_FILE - string - optional
    Path to the file containing the streamlogs log file.
    Default paths:
      * Windows: c:\\programdata\\datadog\\logs\\streamlogs_info\\streamlogs.log
      * Unix: /opt/log/datadog/streamlogs_info/streamlogs.log
      * Linux: /var/log/datadog/streamlogs_info/streamlogs.log
    streamlogs_log_file: <path_to_streamlogs_log_file>

Agent v6.19+/v7.19+ 以降、使用されるデフォルトのトランスポートは HTTPS トランスポートです。HTTPS/TCP トランスポートを実行する方法の詳細については、Agent トランスポートのドキュメントを参照してください。

環境変数を伴った形でログを送信するには、以下の構成を行ってください。

  • DD_LOGS_ENABLED=true

ログ収集を有効にすると、Agent から Datadog にログを転送できるようになります。次に、Agent でログの収集元を設定します。

カスタムログ収集

Datadog Agent v6 は、収集したログをファイル、ネットワーク (TCP または UDP)、journald、Windows チャンネルから Datadog に転送できます。

  1. Agent の構成ディレクトリのルートにある conf.d/ ディレクトリに、Datadog ユーザーがアクセスできる新しい <CUSTOM_LOG_SOURCE>.d/ フォルダを作成します。
  2. この新しいフォルダーに新しい conf.yaml ファイルを作成します。
  3. 下記のパラメーターを指定して、カスタムログ収集構成グループを追加します。
  4. Agent を再起動してこの新しい構成を適用します。
  5. Agent の status サブコマンドを実行し、Checks セクションで <CUSTOM_LOG_SOURCE> を検索します。

権限エラーがある場合は、ログファイルを追跡する権限の問題を参照してトラブルシューティングを行ってください。

以下に、カスタムログ収集設定の例を示します。

<PATH_LOG_FILE>/<LOG_FILE_NAME>.log に保存されているログを <APP_NAME> アプリケーションから収集するには、Agent の構成ディレクトリのルートに以下の内容の <APP_NAME>.d/conf.yaml ファイルを作成します。

logs:
  - type: file
    path: "<PATH_LOG_FILE>/<LOG_FILE_NAME>.log"
    service: "<APP_NAME>"
    source: "<SOURCE>"

Windows では、パス <DRIVE_LETTER>:\\<PATH_LOG_FILE>\\<LOG_FILE_NAME>.log を使用し、ユーザー ddagentuser がログファイルへの読み取りおよび書き込みアクセス権を持つことを確認します。

: ログ行は改行文字、n または \r\n で終了する必要があります。そうしないと、Agent は無期限に待機し、ログ行を送信しません。

TCP ポート 10518 にログを転送する <APP_NAME> アプリケーションからログを収集するには、Agent の構成ディレクトリのルートに以下の内容の <APP_NAME>.d/conf.yaml ファイルを作成します。

logs:
  - type: tcp
    port: 10518
    service: "<APP_NAME>"
    source: "<CUSTOM_SOURCE>"

Serilog を使用している場合、UDP を使用して接続するには、Serilog.Sinks.Network オプションを使用します。

Agent バージョン 7.31.0 以降では、TCP 接続はアイドル状態でも無期限に開いたままになります。

:

  • Agent は、単純文字列、JSON、および Syslog 形式のログをサポートします。複数のログを一度に送信する場合は、改行文字を使用してログを区切ってください。
  • ログ行は改行文字、n または \r\n で終了する必要があります。そうしないと、Agent は無期限に待機し、ログ行を送信しません。

journald からログを収集するには、Agent の構成ディレクトリのルートに以下の内容の journald.d/conf.yaml ファイルを作成します。

logs:
  - type: journald
    path: /var/log/journal/

コンテナ化環境およびユニットフィルタリングの設定については、journald インテグレーションに関するドキュメントを参照してください。

Windows のイベントをログとして Datadog に送信するには、conf.d/win32_event_log.d/conf.yaml にチャンネルを手動で追加するか、Datadog Agent Manager を使用します。

チャンネルリストを表示するには、PowerShell で以下のコマンドを実行します。

Get-WinEvent -ListLog *

最もアクティブなチャンネルを表示するには、PowerShell で以下のコマンドを実行します。

Get-WinEvent -ListLog * | sort RecordCount -Descending

次に、チャンネルを win32_event_log.d/conf.yaml 構成ファイルに追加します。

logs:
  - type: windows_event
    channel_path: "<CHANNEL_1>"
    source: "<CHANNEL_1>"
    service: "<SERVICE>"
    sourcecategory: windowsevent

  - type: windows_event
    channel_path: "<CHANNEL_2>"
    source: "<CHANNEL_2>"
    service: "<SERVICE>"
    sourcecategory: windowsevent

<CHANNEL_X> パラメーターは、イベントの収集に使用する Windows チャンネル名に変更してください。 インテグレーションの自動処理パイプライン設定を利用するには、対応する source パラメーターを同じチャンネル名に設定します。

最後に、Agent を再起動します。

ログの収集に使用可能なパラメーターのリスト

パラメーター必須説明
typeはいログ入力ソースの種類。有効な値は、tcpudpfilewindows_eventdockerjournald です。
portはいtypetcp または udp の場合、ログをリスニングするポートを設定します。
pathはいtypefile または journald の場合、ログを収集するファイルパスを設定します。
channel_pathはいtypewindows_event の場合、ログを収集する Windows イベントチャンネルをリストします。
serviceはいログを所有しているサービスの名前。ご使用のサービスを Datadog APM でインスツルメントしている場合、これは同じサービス名にする必要があります。複数のデータタイプにわたって service を構成する場合は、統合サービスタグ付けの手順を確認してください。
sourceはいログを送信しているインテグレーションを定義する属性。既存のインテグレーションに由来するログでない場合、このフィールドはカスタムソース名を含めることができます。ただし、関連して収集しているカスタムメトリクスがある場合は、そのネームスペースと一致させることをお勧めします。たとえば、myapp.request.countmyapp を使用します。
include_unitsいいえtypejournald の場合、対象とする journald ユニットのリスト。
exclude_pathsいいえtypefile で、path にワイルドカード文字が含まれている場合、ログ収集から除外する必要がある一致するファイルをリストします。6.18 以降の Agent バージョンで使用できます。
exclude_unitsいいえtypejournald の場合、対象としない journald ユニットのリスト。
sourcecategoryいいえソース属性が属するカテゴリーの定義に使用される属性。たとえば、source:postgres、sourcecategory:databasesource: apache, sourcecategory: http_web_access` です。
start_positionいいえ詳しくは開始位置を参照してください。
encodingいいえtypefile の場合、Agent がファイルを読み込む際のエンコーディングを設定します。UTF-16 リトルエンディアン の場合は utf-16-le に、UTF-16 ビッグエンディアンの場合は utf-16-be に、Shift JIS の場合は shift-jis に設定します。その他の値に設定すると、Agent はファイルを UTF-8 形式で読み込みます。utf-16-le および utf-16be は Agent v6.23/v7.23 の、shift-jis は Agent v6.34/v7.34 の追加機能です
tagsいいえ収集される各ログに追加するタグのリスト (タグ付けの詳細はこちら)。

開始位置

start_position パラメーターは file および journald テーラータイプでサポートされています。コンテナをテールする場合、 start_position は常に beginning です。

サポート:

  • File: Agent 6.19+/7.19+
  • Journald: Agent 6.38+/7.38+

typefile の場合

  • Agent がファイルの読み込みを開始する位置を設定します。
  • 有効な値は beginningendforceBeginningforceEnd です (デフォルトは end)。
  • beginning の位置はワイルドカードを使ったパスに対応していません。

typejournald の場合

  • Agent がジャーナルの読み込みを開始する位置を設定します。
  • 有効な値は beginningendforceBeginningforceEnd です (デフォルトは end)。

優先度

file および journald テーラータイプの両方で、end または beginning 位置が指定され、オフセットが格納されている場合、オフセットが優先されます。forceBeginning または forceEnd を使用すると、Agent はオフセットが格納されていても指定された値を使用するようになります。

その他の参考資料