본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

디코더 설정

원문 보기 위키 갱신

파싱하려는 로그 메시지에 인코딩된 데이터가 포함된 경우가 있어요. Docker가 있는 컨테이너 환경에서 전형적인 사용 사례를 찾을 수 있어요. Docker는 이스케이프된 문자열을 사용하는 JSON 형식으로 데이터를 기록해요.

출처: 문서

본문

파싱하려는 로그 메시지에 인코딩된 데이터가 포함된 경우가 있어요. 전형적인 사용 사례는 Docker가 있는 컨테이너 환경에서 찾을 수 있어요. Docker는 이스케이프된 문자열을 사용하는 JSON 형식으로 데이터를 기록해요.

애플리케이션이 생성한 다음 메시지를 살펴보세요.

{"status": "up and running"}

Docker 로그 메시지는 다음과 같은 것을 캡슐화해요.

{"log":"{\"status\": \"up and running\"}\r\n","stream":"stdout","time":"2018-03-09T01:01:44.851160855Z"}

원본 메시지는 이스케이프된 문자열로 처리돼요. Fluent Bit는 문자열이 아닌 원본 구조화 메시지를 사용해요.

시작하기

디코더는 Fluent Bit에서 파서의 기본 제공 기능이에요. 각 파서 정의는 선택적으로 하나 이상의 디코더를 설정할 수 있어요. 다음 디코더 타입 중 하나를 선택하세요.

  • decode_field: 콘텐츠를 구조화 메시지로 디코딩할 수 있으면 구조화 메시지(키와 값)를 원본 로그 메시지에 추가해요.
  • decode_field_as: 디코딩된 콘텐츠(비구조화 또는 구조화)가 동일한 키/값 내에서 대체되며, 추가 키는 추가되지 않아요.

파서에서 decode_field 키가 있는 각 줄은 주어진 필드에 특정 디코더를 적용하도록 파서에 지시해요. 선택적으로 디코더가 성공하지 못하면 추가 조치를 취하는 옵션도 제공돼요.

설정 파라미터

디코더 옵션

이름 설명
escaped 이스케이프된 문자열을 디코딩해요.
escaped_utf8 UTF-8 이스케이프된 문자열을 디코딩해요.
json 필드 콘텐츠를 JSON 맵으로 처리해요. 디코더가 JSON 맵을 찾으면 콘텐츠를 구조화된 맵으로 대체해요.
mysql_quoted MySQL 따옴표 문자열을 디코딩해요.

선택 조치

디코더가 필드를 디코딩하지 못했거나 다른 디코더를 시도하려면 선택 조치를 정의할 수 있어요. 사용 가능한 조치는 다음과 같아요.

이름 설명
do_next 디코더가 성공했든 실패했든, 같은 필드에 대해 목록의 다음 디코더를 적용해요.
try_next 디코더가 실패하면 같은 필드에 대해 목록의 다음 디코더를 적용해요.

조치에는 몇 가지 제한이 적용돼요.

  • decode_field_as: 성공하면, 데이터가 계속 비구조화 메시지(원시 텍스트)인 경우에만 같은 타입의 다른 디코더와 같은 필드가 적용될 수 있어요.
  • decode_field: 성공하면 같은 필드에 한 번만 적용될 수 있어요. decode_field는 구조화 메시지를 디코딩하기 위한 것이에요.

예제

Docker 파서

미리 정의된 Docker 파서는 다음과 같은 정의를 가져요.

{% tabs %} {% tab title="parsers.yaml" %}

parsers:
  - name: docker
    format: json
    time_key: time
    time_format: '%Y-%m-%dT%H:%M:%S.%L'
    time_keep: on
    # Command   |  Decoder | Field | Optional Action   |
    # ==========|==========|=======|===================|
    decode_field_as: escaped log

{% endtab %}

{% tab title="parsers.conf" %}

[PARSER]
  Name         docker
  Format       json
  Time_Key     time
  Time_Format  %Y-%m-%dT%H:%M:%S.%L
  Time_Keep    On
  # Command       |  Decoder  | Field | Optional Action   |
  # ==============|===========|=======|===================|
  Decode_Field_As    escaped     log

{% endtab %} {% endtabs %}

escaped_utf8

/path/to/log.log의 예제 입력:

{"log":"\u0009Checking indexes...\n","stream":"stdout","time":"2018-02-19T23:25:29.1845444Z"}
{"log":"\u0009\u0009Validated: _audit _internal _introspection _telemetry _thefishbucket history main snmp_data summary\n","stream":"stdout","time":"2018-02-19T23:25:29.1845536Z"}
{"log":"\u0009Done\n","stream":"stdout","time":"2018-02-19T23:25:29.1845622Z"}

예제 출력:

...
[24] tail.0: [1519082729.184544400, {"log"=>"   Checking indexes...
", "stream"=>"stdout", "time"=>"2018-02-19T23:25:29.1845444Z"}]
[25] tail.0: [1519082729.184553600, {"log"=>"           Validated: _audit _internal _introspection _telemetry _thefishbucket history main snmp_data summary
", "stream"=>"stdout", "time"=>"2018-02-19T23:25:29.1845536Z"}]
[26] tail.0: [1519082729.184562200, {"log"=>"   Done
", "stream"=>"stdout", "time"=>"2018-02-19T23:25:29.1845622Z"}]
...

디코더 예제 Fluent Bit 설정 파일:

{% tabs %} {% tab title="fluent-bit.yaml" %}

service:
  # Replace with the correct value
  # parsers_file: /fluent-bit/etc/parsers.yaml
  parsers_file: /fluent-bit/etc/parsers.conf

pipeline:
  inputs:
    - name: tail
      parser: docker
      path: /path/to/log.log

  outputs:
    - name: stdout
      match: '*'

{% endtab %}

{% tab title="fluent-bit.conf" %}

[SERVICE]
  Parsers_File /fluent-bit/etc/parsers.conf

[INPUT]
  Name        tail
  Parser      docker
  Path        /path/to/log.log

[OUTPUT]
  Name   stdout
  Match  *

{% endtab %} {% endtabs %}

예제 파서 파일:

{% tabs %} {% tab title="parsers.yaml" %}

parsers:
  - name: docker
    format: json
    time_key: time
    time_format: '%Y-%m-%dT%H:%M:%S %z'
    decode_field_as: escaped_utf8 log

{% endtab %}

{% tab title="parsers.conf" %}

[PARSER]
  Name        docker
  Format      json
  Time_Key    time
  Time_Format %Y-%m-%dT%H:%M:%S %z
  Decode_Field_As escaped_utf8 log

{% endtab %} {% endtabs %}

더 알아보기 (Learn more)