타입 변환기 (Type converter)
지원 이벤트 유형:
logs
Type converter 필터 플러그인은 데이터 타입을 변환하고 새로운 키-값 쌍을 추가해 줘요.
이 필터는 들어오는 문자열 값(string value)을 기대하는 플러그인들과 함께 조합해서 사용할 수 있어요. 예를 들어 Grep이나 Modify 같은 플러그인이 그래요.
출처: 문서
본문
구성 파라미터
이 플러그인은 다음 구성 파라미터를 지원해요. 네 개의 파라미터가 필요해요.
<config_parameter> <src_key_name> <dst_key_name> <dst_data_type>`
dst_data_type는 int, uint, float, string을 허용해요. 예를 들어 int_key id id_str string 같은 형태예요.
| Key | Description |
|---|---|
float_key |
This parameter is for a float source. |
int_key |
This parameter is for an integer source. |
str_key |
This parameter is for a string source. |
uint_key |
This parameter is for an unsigned integer source. |
시작하기 (Get started)
레코드 필터링을 시작하려면 명령줄에서 또는 설정 파일을 통해 필터를 실행할 수 있어요.
필터링할 샘플 in_mem 레코드는 다음과 같아요.
{"Mem.total"=>1016024, "Mem.used"=>716672, "Mem.free"=>299352, "Swap.total"=>2064380, "Swap.used"=>32656, "Swap.free"=>2031724}
이 플러그인은 uint 값을 출력하고, filter_type_converter가 이 값을 string 타입으로 변환해 줘요.
uint를 문자열로 변환하기
fluent-bit.yaml:
pipeline:
inputs:
- name: mem
filters:
- name: type_converter
match: '*'
uint_key:
- Mem.total Mem.total_str string
- Mem.used Mem.used_str string
- Mem.free Mem.free_str string
outputs:
- name: stdout
match: '*'
fluent-bit.conf:
[INPUT]
Name mem
[FILTER]
Name type_converter
Match *
Uint_Key Mem.total Mem.total_str string
Uint_Key Mem.used Mem.used_str string
Uint_Key Mem.free Mem.free_str string
[OUTPUT]
Name stdout
Match *
명령줄에서도 필터를 실행할 수 있어요.
fluent-bit -i mem -o stdout -F type_converter -p 'uint_key=Mem.total Mem.total_str string' -p 'uint_key=Mem.used Mem.used_str string' -p 'uint_key=Mem.free Mem.free_str string' -m '*'
출력은 다음과 같아요.
[0] mem.0: [1639915154.160159749, {"Mem.total"=>8146052, "Mem.used"=>4513564, "Mem.free"=>3632488, "Swap.total"=>1918356, "Swap.used"=>0, "Swap.free"=>1918356, "Mem.total_str"=>"8146052", "Mem.used_str"=>"4513564", "Mem.free_str"=>"3632488"}]