Log/fluentd

02. Fluentd input plugins

우라릭 2022. 10. 8. 20:10

본 글은 https://docs.fluentd.org/을 번역/요약/정리/사견 추가한 글입니다.

 

1. 도입

Fluentd는 9가지 종류의 플러그인이 있습니다. 그 중 input 플러그인에 대해 살펴보겠습니다.Input 플러그인은 이벤트를 받거나 가져옵니다. 이번엔 공식 문서에서 비교적 자세히 설명된 플러그인들만 소개하겠습니다. 다른 플러그인들은 플러그인에서 볼 수 있습니다.

2. in_tail

in_tail 플러그인은 텍스트 파일의 끝부터 이벤트를 읽을 수 있게 해줍니다. 

<source>
  @type tail
  path /var/log/httpd-access.log
  pos_file /var/log/td-agent/httpd-access.log.pos
  tag apache.access
  <parse>
    @type apache2
  </parse>
</source>

위와 같은 설정을 통해 in_tail을 쓸 수 있습니다.  in_tail은 로그 파일의 시작이 아닌 끝부터 읽어 나갑니다. 로그 파일이 rotate되면 새로운 파일을 처음부터 읽습니다.

3. in_forward

in_forward 플러그인은 TCP 소켓을 열어놔 event stream을 받습니다. UDP로 heartbeat message(동기화? health check?)를 받기도 합니다. 이 플러그인은 주로 다른 fluentd instance로부터 이벤트 로그를 받기 위해 사용합니다.

<source>
  @type forward
  port 24224
  bind 0.0.0.0
</source>

4. in_udp, in_tcp

in_udp, in_tcp는 raw payload를 받을 수 있게 해줍니다.

<source>
  @type udp
  tag mytag # required
  <parse>
    @type regexp
    expression /^(?<field1>\d+):(?<field2>\w+)$/
  </parse>
  port 20001               # optional. 5160 by default
  bind 0.0.0.0             # optional. 0.0.0.0 by default
  message_length_limit 1MB # optional. 4096 bytes by default
</source>

5. in_unix

in_unix는 Unix Domain Socket을 받을 수 있게 해줍니다. 

참고: UDS는 프로세스간의 통신을 위한 소켓입니다. 로컬로 쓰기때문에 TCP 소켓에 비해 매우 빠릅니다.

<source>
  @type unix
  path /path/to/socket.sock
</source>

6. in_http

in_http는 HTTP 요청을 이용해 이벤트를 받을 수 있게 해줍니다. 

<source>
  @type http
  port 9880
  bind 0.0.0.0
  body_size_limit 32m
  keepalive_timeout 10s
</source>

app.log 태그를 가지는 요청의 예) curl -X POST -d 'json={"foo":"bar"}' http://localhost:9880/app.log

7. in_syslog

in_syslog는 UDP나 TCP의 syslog 프로토콜을 통해 record를 받을 수 있게 해줍니다.

<source>
  @type syslog
  port 5140
  bind 0.0.0.0
  tag system
</source>

다음과 같은 설정에서 5140 소켓에 메시지를 보내려면 syslog 대몬을 켜야합니다. 

8. in_exec

in_exec은 이벤트를 가져오거나 받기 위해 외부 프로그램을 실행합니다. 그리고 그 프로그램에서 나오는 TSV(tab-serperated values), JSON 등등을 읽습니다.

<source>
  @type exec
  command cmd arg arg
  <parse>
    keys k1,k2,k3
  </parse>
  <extract>
    tag_key k1
    time_key k2
    time_format %Y-%m-%d %H:%M:%S
  </extract>
  run_interval 10s
</source>

9. in_sample

in_sample은 샘플 이벤트를 생성합니다. 테스트, 디버그, 벤치마크를 할 때 유용합니다.

<source>
  @type sample
  sample {"hello":"world"}
  tag sample
</source>

# If you use fluentd v1.11.1 or earlier, use following configuration
<source>
  @type dummy
  dummy {"hello":"world"}
  tag dummy
</source>

10. in_monitor_agent

in_minitor_agent는 Fluentd의 내부 metrics를 REST API를 통해 내보냅니다. Fluentd 자신의 상태를 모니터링하는 용도로 사용하는 것 같습니다.

<source>
  @type monitor_agent
  bind 0.0.0.0
  port 24220
</source>

11. in_windows_eventlog

in_windows_eventlog는 Windows Eventg Log로부터 이벤트를 읽을 수 있게 해줍니다.

<source>
  @type windows_eventlog
  @id windows_eventlog
  channels application,system,security
  tag winevt.raw
  <storage>
    @type local
    persistent true
    path C:\opt\td-agent\winevt.pos
  </storage>
</source>

 

'Log > fluentd' 카테고리의 다른 글

06. Fluentd parser plugins  (0) 2022.10.09
05. Fluentd buffer plugins  (0) 2022.10.08
04. Fluentd filter plugins  (0) 2022.10.08
03. Fluentd output plugins  (0) 2022.10.08
01. Fluentd란?  (1) 2022.10.08