Closed4

FireLens によるカスタムログルーティングを試す

harayuharayu

業務で使用されているが、よく分かっていなかったので調査する
https://aws.amazon.com/jp/blogs/news/under-the-hood-firelens-for-amazon-ecs-tasks/

FireLensによってFluentd, Fluentd Bitを使用してさまざまな宛先にログを送信することができる。

  • ログの宛先はCloudWatch Logs, S3など色々
  • こちら の例を参考にして設定することができる
  • ログにはECSメタデータを付与できる

Fluentd・Fluent Bit
https://docs.fluentd.org/quickstart
https://docs.fluentbit.io/manual
ログを集約・整形して他サービスに送信するサービスぽい

リソース使用量が大幅に少ないためFluent BitをAWSは推奨している。 プラグインがFluentdに比べて少ないが、そこは対応していってくれるぽい

harayuharayu

Fluent Bitの処理は常に上記流れになる。オプションのユーザー提供の設定ファイルに、ログソース、フィルター、およびアウトプットを追加できるのはfluent bit特有らしい

harayuharayu

https://github.com/aws/aws-for-fluent-bit/blob/mainline/use_cases/init-process-for-fluent-bit/README.md#init-process-for-fluent-bit-on-ecs-multi-config-support

複数のconfig fileを使用するにはinitタグがついたimageを使用する
fluent bitのconfigを追加するのにカスタムimageを作成する必要はなく、S3にconfigファイルをおきtaskから参照することができる。

Config files which stored in your S3 bucket You need to set the name of the env var using prefix aws_fluent_bit_init_s3_, the number after this prefix cannot be repeated, and set the ARN of your config file as the value of the env var.

上記命名で環境変数に追加すれば良さそう

harayuharayu

https://tech.nri-net.com/entry/aws_firelens_output_ecs_logs_to_s3_cloudwatch
上記参考にしてs3, cloudwatch log両方にログをはかせることができた。

若干つまづいた点

  • log_routerコンテからs3等にログを出力するためtask roleを追加する必要あり
  • 環境変数にはオブジェクトのarnを指定する。バケットarnを指定してしまっててずっとparse errorなってた
  • s3へのログ出力はcloudwatchより遅かった
このスクラップは4ヶ月前にクローズされました