본문 바로가기
EFK

[EFK] fluent bit을 사용해 로그를 elastic search 보내기

by devjh 2022. 6. 16.
반응형

이번 게시글에서는 fluent bit에서 나온 데이터를 elastic search로 보내는 방법에 대해 정리합니다.

 

fluent-bit 사용법은 이전 게시글을 참고해주세요

 

[devops] fluent bit 으로 k8s(eks)로그 관리하기(bluent-bit 사용법, EFK)

이번 게시글에서는 fluent-bit 사용법에 대해 정리합니다. 1. fluent-bit이란 일반적으로 로깅은 Elastic search, LogStatsh, Kibana의 앞자리를 가져온 ELK 스택이 많이 사용됩니다. 그러나  k8s 클러스터 환경..

frozenpond.tistory.com

 

대표적인 4가지 방법은 아래와 같습니다 하나씩 장단점을 정리합니다.

(1). 바로 es로 보내는 방법

(2). cloudwatch 로그 그룹으로 보낸후 labmda 구독을 통해 es로 보내는 방법

(3). http request를 통해 타 애플리케이션으로 보낸후 es로 보내는 방법

(4). kinesis firehose(delivery stream)을 이용해 es로 보내는 방법

 

1. 바로 es로 보내는 방법

 

Elasticsearch - Fluent Bit: Official Manual

{"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"Action/metadata line [1] contains an unknown parameter [_type]"}],"type":"illegal_argument_exception","reason":"Action/metadata line [1] contains an unknown parameter [_type]"},"status"

docs.fluentbit.io

fluent bit에서 OUTPUT으로 es를 선택해서 보내줍니다.

(index와 index pattern등 kibana setting은 아래의 게시글에서 확인할 수 있습니다)

 

 

fluent bit에서 직접 es로 가게되므로 모든 로그가 es에 적재되게 되므로 불필요한 로그까지 es에 적재될수 있습니다.

 

2. cloudwatch 로그 그룹으로 보낸후 lambda 구독을 통해 es로 보내는 방법

 

Amazon CloudWatch - Fluent Bit: Official Manual

If set to a number greater than zero, and newly create log group's retention policy is set to this many days. Valid values are: [1, 3, 5, 7, 14, 30, 60, 90, 120, 150, 180, 365, 400, 545, 731, 1827, 3653]

docs.fluentbit.io

aws에서 권장하고, example을 제공해주는 방법이라 공식문서를 따라가면 손쉽게 구축할 수 있습니다.

cloudwatch로 모든 fluent bit의 결과를 보내주고 해당 로그그룹에 lambda를 구독시켜 es로 보내는 과정을 개발한다면 불필요한 로그를 drop시키고 원하는 포맷팅으로 변경시켜 es로 보낼수 있다는 장점이 있으며 lambda를 직접 만들기에 자유도가 높습니다.

하지만 cloudwatch는 매우 비싼 서비스이며 fluent bit의 output으로 선택하면 cloudwatch는 초당 5번의 request까지만 받아준다는 단점이 있습니다.

초당 5회가 넘는 request에 대해서는 retry를 하게 되는데 fluent bit에 계속해서 초당 5개 이상의 requerst가 쌓인다면

fluent bit이 버티지 못하게 됩니다(retry정보를 노드에 저장하여 retry횟수가 많아지면 클러스터 전체가 위험해질 수도 있습니다.)
또한 cloudwatch와 kibana 양쪽에서 로그를 확인할수 있다는 장점이 있지만 비용이 비싸다는 단점이 있습니다.

 

3. http request를 통해 타 애플리케이션으로 보낸후 es로 보내는 방법

 

HTTP - Fluent Bit: Official Manual

Specify the AWS service code, i.e. es, xray, etc., of your service, used by SigV4 authentication. Usually can be found in the service endpoint's subdomains, protocol://service-code.region-code.amazonaws.com

docs.fluentbit.io

fluent bit에서 output으로 http를 선택할 수 있습니다.

http request를 받아서 es로 보내주는 로그 서버를 만들어주면 됩니다.

가장 저렴한 방법이지만 로그가 단건단건 http body로 들어가는 형태이므로 kafka를 사용하던, 스케일링을 하던 추가 적인 방어로직이 필요합니다.

 

4. kinesis firehose(delivery stream)을 이용해 es로 보내는 방법

 

Amazon Kinesis Data Firehose - Fluent Bit: Official Manual

By default, the whole log record will be sent to Firehose. If you specify a key name with this option, then only the value of that key will be sent to Firehose. For example, if you are using the Fluentd Docker log driver, you can specify log_key log and on

docs.fluentbit.io

aws에서 제공하는 kinesis firehose를 이용해 es로 보내주는 방법입니다.

kinesis firehose는 대용량 데이터 스트림을 s3나 elasticsearch에 전달하여 적재하기 위한 서비스로 fluent bit의 버퍼역활을 하기에 적합합니다.

 

cloudwatch + lambda 보다 1/6 수준으로 저렴하며 lambda를 이용해 불필요한 로그를 drop시키거나 원하는 es 포맷팅으로 변경시킬수도 있습니다

 

firehose에는 초당 1MB/sec의 데이터를 input할수 있으며, quota를 통해 증대시킬 수 있습니다.

 

destination에 에러가 생기면 retry큐에 넣어 데이터를 다시 보내주는 기능을 지원하며 s3에 저장기능을 지원하여

 

추후 athena 를 이용해 로그를 조회해 갈 수도 있습니다.

 

아래는 kinesis firehose의 사용법입니다.

 

[devops] kinesis firehose를 사용하여 fluent-bit 로그를 es로 보내기(datatransfer with lambda)

이번 게시글에서는 kinesis firehose를 사용하여 fluent bit 로그를 es로 보내는 방법에 대해 정리합니다. fluent bit 의 output 설정은 이전게시글을 참고해주세요 1 .kinesis firehose란 대용량 스트리밍 데이..

frozenpond.tistory.com

 

반응형

댓글