호스트 에이전트 로그 수집

로그 수집에는 Datadog 에이전트 v6.0 이상이 필요합니다. 이전 버전의 에이전트에는 log collection 인터페이스가 포함되어 있지 않습니다. 아직 에이전트를 사용하고 있지 않다면, 에이전트 설치 지침을 따르세요.

다른 공급업체의 수집기 또는 전달자를 사용하여 로그를 전송하려는 경우 또는 배송 전에 사용자 환경 내에서 로그 데이터를 전처리하려는 경우 관찰 가능성 파이프라인을 참조하세요.

로그 수집 활성화

Datadog 에이전트에서는 기본적으로 로그 수집이 활성화되지 않습니다. 쿠버네티스(Kubernetes) 또는 도커(Docker) 환경에서 에이전트를 실행하는 경우 전용 쿠버네티스 로그 수집 또는 도커 로그 수집 설명서를 참조하세요.

호스트에서 실행 중인 에이전트로 로그 수집을 활성화하려면 에이전트의 기본 설정 파일(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. The logs are forwarded in TCP
  ## therefore the proxy must be able to handle TCP connections.
  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 force_use_http - boolean - optional - default: false
  ## @env DD_LOGS_CONFIG_FORCE_USE_HTTP - boolean - optional - default: false
  ## By default, the Agent sends logs in HTTPS batches to port 443 if HTTPS connectivity can
  ## be established at Agent startup, and falls back to TCP otherwise. Set this parameter to `true` to
  ## always send logs with HTTPS (recommended).
  ## Warning: force_use_http means HTTP over TCP, not HTTP over HTTPS. Please use logs_no_ssl for HTTP over HTTPS.
  force_use_http: true

  ## @param force_use_tcp - boolean - optional - default: false
  ## @env DD_LOGS_CONFIG_FORCE_USE_TCP - boolean - optional - default: false
  ## By default, logs are sent through HTTPS 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 with HTTPS. 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 the Datadog Agent waits to fill each batch of logs before sending.
  batch_wait: 5

  ## @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: 256000
  ## @env DD_LOGS_CONFIG_MAX_MESSAGE_SIZE_BYTES - integer - optional - default : 256000
  ## 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: 256000

에이전트 v6.19+/v7.19+부터는 HTTPS 전송이 기본 전송으로 사용됩니다. HTTPS/TCP 전송을 강제하는 방법에 대한 자세한 내용은 에이전트 전송 문서를 참조하세요.

환경 변수와 로그를 보내려면 다음과 같이 설정하세요.

  • DD_LOGS_ENABLED=true

로그 수집을 활성화하면, 에이전트가 Datadog에 로그를 전달할 준비가 됩니다. 다음으로 로그를 수집할 에이전트를 설정합니다.

커스텀 로그 수집

Datadog 에이전트 v6는 로그를 수집하여 파일, 네트워크(TCP 또는 UDP), journald 및 윈도우즈(Windows) 채널에서 Datadog로 전달할 수 있습니다:

  1. 에이전트 설정 디렉터리의 루트에 있는 conf.d/ 디렉터리에 Datadog 사용자가 액세스할 수 있는 새 <CUSTOM_LOG_SOURCE>.d/ 폴더를 생성합니다.
  2. 이 새 폴더에 새로운 conf.yaml 파일을 만듭니다.
  3. 아래 파라미터를 사용하여 커스텀 로그 수집 설정 그룹을 추가합니다.
  4. 이 새로운 설정을 고려하려면 에이전트를 다시 시작하세요.
  5. 에이전트 상태 하위 명령을 실행하고 확인 섹션에서 <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 사용자에게 로그 파일에 대한 읽기 및 쓰기 액세스 권한이 있는지 확인하세요.

로그를 TCP 포트 10518로 전달하는 <APP_NAME> 애플리케이션에서 로그를 수집하려면, 에이전트 설정 디렉토리의 루트에 다음 내용이 포함된<APP_NAME>.d/conf.yaml 파일을 생성합니다:

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

Serilog를 사용하는 경우, Serilog.Sinks.Network는 UDP로 연결하기 위한 옵션입니다.

에이전트 버전 7.31.0+에서 TCP 연결은 유휴 상태에서도 무기한 열린 상태를 유지합니다.

참고: 에이전트는 원시 문자열, JSON 및 Syslog 형식의 로그를 지원합니다. 로그를 배치로 보내는 경우, 줄 바꿈 문자를 사용하여 로그를 구분하세요.

journald에서 로그를 수집하려면, 에이전트 설정 디렉토리의 루트에 다음 내용이 포함된 journald.d/conf.yaml 파일을 생성합니다:

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

컨테이너화된 환경 및 단위 필터링 설정에 대한 자세한 내용은 journald 통합 문서를 참조하세요.

Windows 이벤트를 로그로 Datadog에 보내려면, 채널을 conf.d/win32_event_log.d/conf.yaml에 수동으로 추가하거나 Datadog 에이전트 매니저를 사용하세요.

채널 목록을 보려면 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

이벤트를 수집하려는 Windows 채널 이름으로 <CHANNEL_X> 파라미터를 편집합니다. 해당 source 파라미터를 동일한 채널 이름으로 설정하여 통합 자동 처리 파이프라인 설정의 이점을 얻습니다.

마지막으로 에이전트를 다시 시작합니다.

로그 수집에 사용 가능한 모든 파라미터 목록:

파라미터필수설명
typeYes로그 입력 소스의 유형입니다. 유효한 값은 tcp, udp, file, windows_event, docker, 또는 journald입니다.
portYestypetcp 또는 udp인 경우, 로그를 수신할 포트를 설정합니다.
pathYestype파일 또는 journald인 경우, 로그를 모으기 위한 파일 경로를 설정합니다.
channel_pathYestypewindows_event인 경우, 로그 수집을 위한 Windows 이벤트 채널을 목록으로 표시합니다.
serviceYes로그를 소유한 서비스의 이름입니다. Datadog APM으로 서비스를 계측한 경우 서비스 이름이 동일해야 합니다. 여러 데이터 유형에 걸쳐 service를 설정하는 경우 통합 서비스 태깅 지침을 확인하세요.
sourceYes로그를 보내는 통합을 정의하는 속성입니다. 로그가 기존 통합에서 제공되지 않은 경우 이 필드에 커스텀 소스 이름이 포함될 수 있습니다. 그러나 이 값을 수집 중인 관련 커스텀 메트릭의 네임스페이스와 일치시키는 것이 좋습니다(예: myapp.request.countmyapp).
include_units아니요typejournald인 경우, 포함할 특정 journald 단위의 목록을 표시합니다.
exclude_paths아니요type파일이고, path가 와일드카드 문자를 포함하는 경우, 로그 수집에서 제외할 일치하는 파일의 목록을 표시합니다. 에이전트 버전 6.18 이상에서 사용할 수 있습니다.
exclude_units아니요typejournald인 경우, 제외할 특정 journald 단위의 목록을 표시합니다.
sourcecategory아니요소스 속성이 속한 범주를 정의하는 데 사용되는 속성입니다, 예를 들어: source:postgres, sourcecategory:database 또는 source: apache, sourcecategory: http_web_access입니다.
start_position아니요자세한 내용은 시작 포지션를 참조하세요.
encoding아니요type파일인 경우, 에이전트가 파일을 읽을 수 있도록 인코딩을 설정합니다. UTF-16 little-endian은 utf-16-le, UTF-16 big-endian은 utf-16-be, Shift JIS는 shift-jis로 설정합니다. 다른 값으로 설정하면, 에이전트는 파일을 UTF-8로 읽습니다. utf-16-leutf-16be는 에이전트 v6.23/v7.23에 추가됨, shift-jis는 에이전트 v6.34/v7.34에 추가됨
tags아니요수집된 각 로그에 추가된 태그 목록(태그 지정에 대해 자세히 알아보기)

시작 포지션

start_position 파라미터는 filejournald 테일러 유형에서 지원됩니다. 컨테이너를 추적할 때 start_position는 항상 beginning입니다.

지원:

  • File: 에이전트6.19+/7.19+
  • Journald: 에이전트 6.38+/7.38+

typefile인 경우:

  • 에이전트에 대한 포지션을 설정하여 파일 읽기를 시작합니다.
  • 유효한 값은 beginning, end, forceBeginningforceEnd(기본값: end)입니다.
  • beginning 포지션은 와일드카드 포함 경로를 지원하지 않습니다.

typejournald인 경우:

  • 에이전트가 저널 읽기를 시작하는 포지션을 설정합니다.
  • 유효한 값은 beginning, end, forceBeginningforceEnd(기본값: end)입니다.

우선 순위

file 및 journald 테일러 유형 모두에 대해 또는 end 또는 beginning 포지션이 지정되었지만 오프셋이 저장된 경우 오프셋이 우선합니다. 저장된 오프셋이 있는 경우에도 forceBeginning 또는 forceEnd를 사용하면 에이전트가 지정된 값을 사용하도록 합니다.

참고 자료