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

Systemd 입력 플러그인

원문 보기 위키 갱신

Linux 환경의 journald 데몬에서 로그 메시지를 수집하고 싶을 때 쓰는 입력 플러그인입니다. 함께 살펴보겠습니다.

출처: 문서

본문

{% hint style="info" %} Supported event types: logs {% endhint %}

Systemd 입력 플러그인은 Linux 환경의 journald 데몬에서 로그 메시지를 수집할 수 있게 해 줍니다.

Configuration parameters

플러그인은 다음 구성 파라미터를 지원합니다:

Key Description Default
db Specify the absolute path of a database file to keep track of the journald cursor. none
db.sync Set a default synchronization (I/O) method. Possible values: extra, full, normal, and off. This flag affects how the internal SQLite engine synchronizes to disk. For more details, see the SQLite documentation. Available in Fluent Bit v1.4.6 and later. full
lowercase Lowercase the journald field (key). false
max_entries When Fluent Bit starts, the Journal might have a high number of logs in the queue. To avoid delays and reduce memory usage, use this option to specify the maximum number of log entries that can be processed per round. Once the limit is reached, Fluent Bit will continue processing the remaining log entries once journald performs the notification. 5000
max_fields Set a maximum number of fields (keys) allowed per record. 8000
namespace Read from a specific journald namespace instead of the default journal. See Journal namespaces. Can't be used with path. Setting both causes a startup error. none
path Optional path to the Systemd journal directory. If not set, the plugin uses default paths to read local-only logs. none
read_from_tail Start reading new entries. Skip entries already stored in journald. false
strip_underscores Remove the leading underscore of the journald field (key). For example, the journald field _PID becomes the key PID. false
systemd_filter Perform a query over logs that contain specific journald key/value pairs. For example, _SYSTEMD_UNIT=UNIT. The systemd_filter option can be specified multiple times in the input section to apply multiple filters. none
systemd_filter_type Define the filter type when systemd_filter is specified multiple times. Allowed values: and, or. With and a record is matched only when all systemd_filter have a match. With or a record is matched when any systemd_filter has a match. or
tag Fluent Bit uses tags to route messages. For the Systemd input plugin, tags have an additional capability: if the tag includes a wildcard (*), it will be expanded with the Systemd Unit file (_SYSTEMD_UNIT, like host.* => host.UNIT_NAME) or unknown (host.unknown) if _SYSTEMD_UNIT is missing. none
threaded Indicates whether to run this input in its own thread. false

Journal namespaces

Systemd는 저널을 namespaces로 분할할 수 있는데, 이 경우 별도의 systemd-journald 인스턴스가 유닛 집합에 대해 자신만의 로그 저장소를 유지합니다. 기본 저널 대신 이런 네임스페이스 중 하나에서 수집하려면 namespace를 설정하세요.

namespace를 사용할 때 다음 사항을 기억하세요:

  • 플러그인은 이름이 지정된 네임스페이스만 읽습니다. 기본 저널의 항목은 수집되지 않아요. 둘 다 수집하려면 각각에 별도의 systemd 입력을 정의하세요.
  • namespace와 path는 상호 배타적입니다. 둘 다 설정하면 Fluent Bit는 path and namespace are mutually exclusive를 기록하고 시작에 실패합니다.
  • 이 옵션은 sd_journal_open_namespace가 도입된 libsystemd 245 이상으로 빌드된 Fluent Bit 바이너리가 필요합니다. 더 오래된 버전으로 빌드된 경우 Fluent Bit는 namespace requires libsystemd >= 245를 기록하고 시작에 실패합니다. 그런 빌드에서는 path를 대신 사용하세요.
  • db를 사용해 저널 커서를 추적할 때는 각 네임스페이스에 고유한 데이터베이스 파일을 주세요. 네임스페이스 간에 하나의 데이터베이스 파일을 재사용하면 다른 네임스페이스가 탐색할 수 없는 커서가 생성되고, 플러그인은 seek_cursor failed 경고를 기록하고 처음부터 다시 시작합니다.

다음 예시는 logging이라는 네임스페이스에서 로그를 수집하고 그 네임스페이스 전용 데이터베이스 파일에 커서를 기록합니다:

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

pipeline:
  inputs:
    - name: systemd
      tag: host.*
      namespace: logging
      db: /var/lib/fluent-bit/systemd-logging.db
  outputs:
    - name: stdout
      match: '*'

{% endtab %}

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

[INPUT]
  Name       systemd
  Tag        host.*
  Namespace  logging
  DB         /var/lib/fluent-bit/systemd-logging.db

[OUTPUT]
  Name   stdout
  Match  *

{% endtab %} {% endtabs %}

시작하기

Systemd 메시지를 받으려면 명령줄에서 또는 구성 파일을 통해 플러그인을 실행할 수 있어요.

명령줄

명령줄에서 다음 옵션으로 Fluent Bit가 Systemd 메시지를 수신하게 할 수 있습니다:

fluent-bit -i systemd \
           -p systemd_filter=_SYSTEMD_UNIT=docker.service \
           -p tag='host.*' \
           -o stdout

이 예시는 Docker 서비스에서 오는 모든 메시지를 수집합니다.

구성 파일

주 구성 파일에 다음 섹션을 추가합니다:

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

service:
  flush: 1
  log_level: info

pipeline:
  inputs:
    - name: systemd
      tag: host.*
      systemd_filter: _SYSTEMD_UNIT=docker.service
  outputs:
    - name: stdout
      match: '*'

{% endtab %}

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

[SERVICE]
  Flush        1
  Log_Level    info

[INPUT]
  Name            systemd
  Tag             host.*
  Systemd_Filter  _SYSTEMD_UNIT=docker.service

[OUTPUT]
  Name   stdout
  Match  *

{% endtab %} {% endtabs %}

더 알아보기 (Learn more)