본문 바로가기

파이프라인

td-agent 설정

<system>, @include, <source>, <match>, <filter>,  <label> 6가지 디렉티브로 구성

<system>

Fluentd 자체의 동작 및 로그 출력 부분의 상세 설정을 커스터마이즈할 수 있음

Fluentd를 실행할 때 커맨드라인의 파라미터로 /etc/sysconfig/td-agent를 커스터마이즈하는 것과 같은 효과

예제

<system>
log_level info #로그의 출력 레벨을 지정. trace, debug, info, warn, error, fatal
suppress_repeated_stacktrace true #ture 로 설정되면 연속된 같은 에러 생략
emit_error_log_interval 60s #지정된 (초)시간 동안 같은  에러 생략
suppress_config_dump true #true로 설정되면 설정 파일의 표준 로그 출력 생략
without_source true #true로 설정되면 <source> 디렉티브의 지정은 모두 무효
process_name fluentd #명시된 명칭으로 프로세스 이름을 변경
</system>

 

@include

외부의 설정 파일을 읽어들이기 위한 디렉티브

예제

@include /etc/td-agent/custom/config.conf #별도의 conf을 절대 경로로 지정
@include /etc/td-agent/custom2/*.conf #와일드카드로 지정
@include http://127.0.0.1/config2.conf #HTTP 통신으로 설정 지정

 

<source>

Input 플러그인을 지정하고, 설정하는 디렉티브

메세지를 포트로 수신하거나 로그 파일의 내용이 추가되는 것을 감시하는 등의 플러그인으로 구성

tag, time, record 3개의 요소로 구성된 메세지를 fluentd로 전송

예제

<source>
  @id if_forward # plugin_id를 중복되지 않게 지정
  @type forward # 플러그인 이름은 forward, tail이 많이 사용. https://docs.fluentd.org/input 참고
     #forward는 fluentd 클라이언트나 다른 인스턴스에서 받는 플러그인
     #tail은 로그 파일에 추가되는 내용을 차례대로 읽는 플러그인. "pos_file 경로"를 옵션으로 지정해서 위치 저장
  tag myaccess.type # tag를 지정하여 Fluentd 엔진에서 처리하는 라우팅 역할
  @label @mylabel #라벨을 지정하여 filter, match 등의 디렉티브를 포함하여 처리하는 라우팅 표현을 단순화
</source>

<source>
  #tail type 예제
  @id in_tail_test
  @type tail
  format apache
  path /var/log/example/error.log
  pos_file /var/log/td-agent/custom/test.pos
  tag apache.test
</source>

 

<filter>

특정 태그만 처리하는 디렉티브로 match 전에 명시되어 레코드 내용을 편집하는 등의 역할을 수행

예제

<filter access.test> # source에서 access.test로 tag명을 지정한 레코드에 대해 host 명을 host 키에 추가
  @type record_transformer
  <record>
    host ${hostname}
  </record>
</filter>

 

<match>

로그의 출력을 지정하는 디렉티브로 클라우드 스토리지, DB에 저장하거나 파일 등으로 저장

match 태그 순서에 매칭되어 버리면 이후 태그 패턴에서는 처리되지 않으므로 주의

예제

<match access.test>
  #* 은 하나의 요소와 일치. ex) access.* -> access.a, access.b ~~ 등과 매칭
  #** 은 여러개의 요소와 일치. ex) access.** -> access.a.b, access.a.b.c ~~ 등과 매칭
  #{a,b} 은 or 조건으로 각 요소와 일치. ex) access.a.{b,c} -> access.a.b, access.a.c와 매칭
  
  @id in_match # plug id 지정
  @type stdout # 출력 플러그인 지정. https://docs.fluentd.org/output 참고
</match>

 

<label>

fluentd에서 처리되는 라우팅을 단순하게 표현하기 위해 필요한 기능

<filter>, <match> 디렉티브를 명시해서 사용할 수 있음

예제

<source>
  @type forward
</source>
<source>
  @type tail
  @label @test_label
</source>

#access. 태그의 레코드에 host명을 host키에 추가
<filter access.**>
  @type record_transformer
  <record>
    host ${hostname} 
  </record>
</filter>
#match 디렉티브로 지정 가능
<match **>
 ~~
</match>

#label 디렉티브 내에 filter , match 디렉티브를 명시하여 가시성을 확보하고 단순화
<label @test_label>
  <filter access2.**>
    @type record_transformer
    <record>
      host ${hostname} 
    </record>
  </filter>
  <match **>
    @type stdout
  </match>
</label>

 

 

참고

 

td-agent.conf 문법 - CHO

이 설정 파일을 수정하여 사용자 정의하기 전에 몇가지 문법을 확인해 보자. 설정 파일에서 쓰이는 지시자(Directives) 목록은 다음과 같다. – source : 입력 형태 결정. – match : 출력 목적지 결

www.shotan.org