TCP와 TLS (TCP and TLS)
TCP and TLS 출력 플러그인은 원격 TCP 서버로 레코드를 보낼 수 있게 해줘요. 페이로드는 필요에 따라 여러 가지 방식으로 포맷할 수 있어요.
출처: 문서
본문
TCP and TLS 출력 플러그인은 레코드를 원격 TCP 서버로 보낼 수 있게 해줘요. 페이로드는 필요에 따라 다른 방식으로 포맷할 수 있어요.
Configuration parameters (설정 매개변수)
이 플러그인은 다음 매개변수를 지원해요:
| Key | Description | Default |
|---|---|---|
format |
Specify the data format to be printed. Supported formats: msgpack, json, json_lines, json_stream. |
msgpack |
host |
Target host where Fluent Bit or Fluentd are listening for Forward messages. | 127.0.0.1 |
json_date_format |
Specify the format of the date. Supported formats: double, epoch, epoch_ms, iso8601, java_sql_timestamp. |
double |
json_date_key |
Specify the name of the time key in the output record. To disable the time key, set the value to false. |
date |
port |
TCP port of the target service. | 5170 |
raw_message_key |
If set, the value of this key is sent as the raw message payload without additional formatting. | none |
workers |
The number of workers to perform flush operations for this output. | 2 |
TLS configuration parameters (TLS 설정 매개변수)
TLS를 통한 보안 채널 연결을 구성하는 데 다음 매개변수를 사용할 수 있어요:
| Key | Description | Default |
|---|---|---|
tls |
Enable or disable TLS support. | off |
tls.verify |
Force certificate validation. | on |
tls.debug |
Set TLS debug verbosity level. Allowed values: 0 (No debug), 1 (Error), 2 (State change), 3 (Informational), 4 (Verbose) |
1 |
tls.ca_file |
Absolute path to CA certificate file. | none |
tls.crl_file |
Absolute path to a Certificate Revocation List (CRL) file in PEM format. When set, revoked certificates are rejected during TLS verification. Supported in v5.1.3 or later. | none |
tls.crt_file |
Absolute path to Certificate file. | none |
tls.key_file |
Absolute path to private Key file. | none |
tls.key_passwd |
Optional password for tls.key_file file. |
none |
Getting started (시작하기)
Command line (커맨드 라인)
JSON format (JSON 형식)
이 예시는 CPU 사용량 메트릭을 수집해서 netcat 서비스를 사용하는 원격 엔드포인트로 JSON lines 모드로 보내는 방법을 보여줘요.
fluent-bit -i cpu -o tcp://127.0.0.1:5170 -p format=json_lines -v
별도의 터미널에서 다음을 실행하세요. netcat이 TCP 포트 5170에서 메시지를 기다리기 시작할 거예요. Fluent Bit에 연결된 뒤에는 JSON 형식의 출력을 볼 수 있어요:
nc -l 5170
그러면 다음과 비슷한 결과가 나와요:
...
{"date":1644834856.905985,"cpu_p":1.1875,"user_p":0.5625,"system_p":0.625,"cpu0.p_cpu":0.0,"cpu0.p_user":0.0,"cpu0.p_system":0.0,"cpu1.p_cpu":1.0,"cpu1.p_user":1.0,"cpu1.p_system":0.0,"cpu2.p_cpu":4.0,"cpu2.p_user":2.0,"cpu2.p_system":2.0,"cpu3.p_cpu":1.0,"cpu3.p_user":0.0,"cpu3.p_system":1.0,"cpu4.p_cpu":1.0,"cpu4.p_user":0.0,"cpu4.p_system":1.0,"cpu5.p_cpu":1.0,"cpu5.p_user":1.0,"cpu5.p_system":0.0,"cpu6.p_cpu":0.0,"cpu6.p_user":0.0,"cpu6.p_system":0.0,"cpu7.p_cpu":3.0,"cpu7.p_user":1.0,"cpu7.p_system":2.0,"cpu8.p_cpu":0.0,"cpu8.p_user":0.0,"cpu8.p_system":0.0,"cpu9.p_cpu":1.0,"cpu9.p_user":0.0,"cpu9.p_system":1.0,"cpu10.p_cpu":1.0,"cpu10.p_user":0.0,"cpu10.p_system":1.0,"cpu11.p_cpu":0.0,"cpu11.p_user":0.0,"cpu11.p_system":0.0,"cpu12.p_cpu":0.0,"cpu12.p_user":0.0,"cpu12.p_system":0.0,"cpu13.p_cpu":3.0,"cpu13.p_user":2.0,"cpu13.p_system":1.0,"cpu14.p_cpu":1.0,"cpu14.p_user":1.0,"cpu14.p_system":0.0,"cpu15.p_cpu":0.0,"cpu15.p_user":0.0,"cpu15.p_system":0.0}
...
msgpack format (msgpack 형식)
JSON 방식과 같지만 msgpack 출력 형식을 사용해요.
fluent-bit -i cpu -o tcp://127.0.0.1:5170 -p format=msgpack -v
이걸 stdout으로 보낼 수도 있지만, 직렬화된 형식이라 이상한 출력이 나올 거예요.
이것은 msgpack 수신기가 언패킹(unpack)해서 처리해야 해요. 다음 예시는 Python msgpack 라이브러리로 처리하는 방법이에요:
#Python3
import socket
import msgpack
unpacker = msgpack.Unpacker(use_list=False, raw=False)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(("127.0.0.1", 5170))
s.listen(1)
connection, address = s.accept()
while True:
data = connection.recv(1024)
if not data:
break
unpacker.feed(data)
for unpacked in unpacker:
print(unpacked)
다음 명령들을 실행하세요:
pip install msgpack
python3 test.py
그러면 다음과 같은 결과가 나와요:
...
(ExtType(code=0, data=b'b\n5\xc65\x05\x14\xac'), {'cpu_p': 0.1875, 'user_p': 0.125, 'system_p': 0.0625, 'cpu0.p_cpu': 0.0, 'cpu0.p_user': 0.0, 'cpu0.p_system': 0.0, 'cpu1.p_cpu': 0.0, 'cpu1.p_user': 0.0, 'cpu1.p_system': 0.0, 'cpu2.p_cpu': 1.0, 'cpu2.p_user': 0.0, 'cpu2.p_system': 1.0, 'cpu3.p_cpu': 0.0, 'cpu3.p_user': 0.0, 'cpu3.p_system': 0.0, 'cpu4.p_cpu': 0.0, 'cpu4.p_user': 0.0, 'cpu4.p_system': 0.0, 'cpu5.p_cpu': 0.0, 'cpu5.p_user': 0.0, 'cpu5.p_system': 0.0, 'cpu6.p_cpu': 0.0, 'cpu6.p_user': 0.0, 'cpu6.p_system': 0.0, 'cpu7.p_cpu': 0.0, 'cpu7.p_user': 0.0, 'cpu7.p_system': 0.0, 'cpu8.p_cpu': 0.0, 'cpu8.p_user': 0.0, 'cpu8.p_system': 0.0, 'cpu9.p_cpu': 1.0, 'cpu9.p_user': 1.0, 'cpu9.p_system': 0.0, 'cpu10.p_cpu': 0.0, 'cpu10.p_user': 0.0, 'cpu10.p_system': 0.0, 'cpu11.p_cpu': 0.0, 'cpu11.p_user': 0.0, 'cpu11.p_system': 0.0, 'cpu12.p_cpu': 0.0, 'cpu12.p_user': 0.0, 'cpu12.p_system': 0.0, 'cpu13.p_cpu': 0.0, 'cpu13.p_user': 0.0, 'cpu13.p_system': 0.0, 'cpu14.p_cpu': 0.0, 'cpu14.p_user': 0.0, 'cpu14.p_system': 0.0, 'cpu15.p_cpu': 0.0, 'cpu15.p_user': 0.0, 'cpu15.p_system': 0.0})
...
Configuration file (설정 파일)
다음은 TCP로 로그를 전달하는 기본 설정이에요:
{% tabs %} {% tab title="fluent-bit.yaml" %}
pipeline:
inputs:
- name: cpu
tag: cpu
outputs:
- name: tcp
match: '*'
host: 192.168.10.12
port: 5170
format: json_lines
{% endtab %}
{% tab title="fluent-bit.conf" %}
[INPUT]
Name cpu
Tag cpu
[OUTPUT]
Name tcp
Match *
Host 192.168.10.12
Port 5170
Format json_lines
{% endtab %} {% endtabs %}
Examples (예시)
Raw message key (원시 메시지 키)
raw_message_key를 설정하면 플러그인은 포맷을 적용하는 대신 지정된 키의 값을 원시 메시지로 보내요. 그래서 format 속성은 무시돼요:
{% tabs %} {% tab title="fluent-bit.yaml" %}
pipeline:
inputs:
- name: tail
path: /var/log/app.log
tag: app
outputs:
- name: tcp
match: '*'
host: 127.0.0.1
port: 5170
raw_message_key: $message
{% endtab %}
{% tab title="fluent-bit.conf" %}
[INPUT]
Name tail
Path /var/log/app.log
Tag app
[OUTPUT]
Name tcp
Match *
Host 127.0.0.1
Port 5170
Raw_Message_Key $message
{% endtab %} {% endtabs %}
$ 기호는 레코드 액세서(record accessor)가 지정된 키에서 값을 추출하도록 신호를 보내는데 필요해요. 이 키는 최상위 필드일 수도 있고 중첩 필드일 수도 있어요:
{% tabs %} {% tab title="Top-level field (최상위 필드)" %} 예시 로그:
{
"timestamp": "2026-07-05T14:32:07Z",
"message": "<34>Jul 5 14:32:07 myhost app: Cache key S2VlcCBjYWxtIGFuZCBsb2cgb24="
}
raw_message_key를 $message로 설정하면 다음이 나와요:
<34>Jul 5 14:32:07 myhost app: Cache key S2VlcCBjYWxtIGFuZCBsb2cgb24=
{% endtab %}
{% tab title="Nested field (중첩 필드)" %} 예시 로그:
{
"timestamp": "2026-07-05T14:32:07Z",
"message": {
"original": "<34>Jul 5 14:32:07 myhost app: Cache key S2VlcCBjYWxtIGFuZCBsb2cgb24="
}
}
raw_message_key를 $message['original']로 설정하면 다음이 나와요:
<34>Jul 5 14:32:07 myhost app: Cache key S2VlcCBjYWxtIGFuZCBsb2cgb24=
{% endtab %} {% endtabs %}