Skip to main content

Fluentd


설치

https://kubesphere.io/blogs/deep-dive-into-kubernetes-logging/
helm repo add fluent https://fluent.github.io/helm-charts
helm repo update fluent \
&& helm search repo fluent/fluentd -l | head -n 10
helm show values fluent/fluentd \
--version 0.3.9 \
> fluentd-values.yaml
fluentd-values.yaml
kind: "DaemonSet" # DaemonSet, Deployment or StatefulSet

livenessProbe:
httpGet:
path: /metrics
port: metrics
initialDelaySeconds: 30
timeoutSeconds: 15

readinessProbe:
httpGet:
path: /metrics
port: metrics
initialDelaySeconds: 30
timeoutSeconds: 15

resources:
requests:
cpu: 100m
memory: 512Mi
limits:
memory: 512Mi

podLabels: {}

env:
- # /fluentd/etc/../../etc/fluent/fluent.conf
# /etc/fluent/fluent.conf
name: "FLUENTD_CONF"
value: "../../etc/fluent/fluent.conf"

dashboards:
enabled: "false"

plugins: []

configMapConfigs: []

fileConfigs:
01_sources.conf: |

02_filters.conf: |

03_dispatch.conf: |

04_outputs.conf: |
helm upgrade fluentd fluent/fluentd \
--install \
--version 0.3.9 \
-n monitoring \
--history-max 5 \
-f fluentd-values.yaml

설정

Input -> filter 1 -> ... -> filter N -> Output
  • <source>: 어떤 정보를 입력받을지 설정
    • @type이 필수 입니다.
  • <filter <tag pattern>>: 발생한 이벤트를 어떻게 처리할지 설정
  • <match <tag pattern>>: 처리된 값을 어떻게 사용할지 설정
  • <system>: 시스템 설정
  • <label>: 내부 라우팅을 위해 필터와 출력 그룹 설정
  • @include path|glob|url: 다른 설정파일 호출
warning

filter와 match는 선언 순서가 중요합니다. match 지시문의 패턴에 걸린 경우 그 다음 선언된 지시문은 실행되지 않습니다.

Tag pattern

  • tag는 .으로 구분 됩니다.
  • *: 태그 한 파트에 대한 glob입니다.
    • a.*a.b, a.c와 매치되지만 a, a.b.c는 매치되지 않습니다.
  • **: 태그 0 개 이상 파트에 대한 glob입니다.
    • a.**a, a.b, a.b.c 등과 매치됩니다.
  • {X, Y}: X 또는 Y입니다.
    • a.{b, c} {a, b.*} 등으로 사용할 수 있습니다.
  • /regex/
  • #{...}: ruby 표현식으로 문자열을 나타낼 수 있습니다.

Common Parameters


  • @type: 사용할 플러그인
  • @id: 식별자
  • @log_level
  • @label
warning

conf 파일을 수정하면 fluentd를 재시작 해주세요.

source(input)

forward

fluentd-values.yaml
kind: "Deployment"

service:
ports:
- name: "forwarder"
protocol: TCP
containerPort: 24224
# https://docs.fluentd.org/input/forward
<source>
@type forward
port 24224
bind 0.0.0.0
</source>

buffer

<buffer>
flush_at_shutdown true
flush_interval 10s
flush_thread_count 4
retry_max_interval 30s
</buffer>

output

copy

동일한 tag 패턴을 갖는 match는 먼저 선언된 것만 실행되기 때문에, 여러 output을 사용하고 싶다면 copy를 사용합니다.

<match pattern>
@type copy
<store>
@type <output>
...
</store>
<store>
@type <output>
...
</store>
<store>
@type <output>
...
</store>
</match>