10
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

FluentdでサクッとログをCloudwatchLogsに流す

Last updated at Posted at 2018-05-31

よく忘れるので備忘録

Fluentdのインストール

https://docs.fluentd.org/v0.12/articles/quickstart#step1:-installing-fluentd
gemでもインストールできるけどtd-agentの方がプロセス管理しやすいのでrpm Packageを使う

$ curl -L https://toolbelt.treasuredata.com/sh/install-redhat-td-agent2.sh | sh

fluent-plugin-cloudwatch-logsのインストール

普通に $ gem install するとtd-agentがgemを見つけられない

$ service td-agent start
Starting td-agent: 2018-05-31 01:27:51 +0000 [error]: fluent/supervisor.rb:373:rescue in main_process: config error file="/etc/td-agent/td-agent.conf" error="Unknown output plugin 'cloudwatch_logs'. Run 'gem search -rd fluent-plugin' to find plugins"
td-agent                                                   [FAILED]

fluentdのdocを見ると以下のような記載があるので

# If Using td-agent, Use /usr/sbin/td-agent-gem
If you are using td-agent, please make sure to use td-agent’s td-agent-gem command. Otherwise (e.g. you use the command belonging to system, rvm, etc.), you won’t be able to find your “installed” plugins.

これでOK

$ td-agent-gem install fluent-plugin-cloudwatch-logs

IAMでfluentdユーザーを作成して環境変数にアクセスキーを設定しておく

configの設定

/etc/td-agent/td-agent.conf にconfigがあるので設定

<source>
  @type tail
  format none
  path /var/log/test.log
  pos_file /var/log/test.log.pos
  tag /var/log/test.log
</source>

<match **.log>
  @type cloudwatch_logs
  log_group_name test
  auto_create_stream true
  use_tag_as_stream true
</match>

起動してcloudwatchlogsにログが流れるのを確認

$ service td-agent start
td-agent td-agent:                                         [  OK  ]
10
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?