Skip to content
Last updated

ローカルおよびリモートでのログ保存のためのTD Agent

Treasure Agent(td-agent)の'copy'機能を使用して、td-agentがクラウドにデータをアップロードする際に、ログをローカルに保存できます。

前提条件

  • Treasure Dataの基本的な知識。

  • ログコレクターであるtd-agentの基本的な知識。

ローカルディスクとTreasure Data

以下の設定は、ログをローカルディスク(/mnt/archive/logs)とTreasure Dataに保存する方法を示しています。ローカルファイルは1時間ごとに作成されます。

<match td.*.*>
  type copy
  <store>
    type file
    path /mnt/archive/logs
    time_slice_format %Y%m%d%h
  </store>
  <store>
    type tdlog
    endpoint api.treasuredata.com
    apikey YOUR_API_KEY_HERE
    auto_create_table
    buffer_type file
    buffer_path /var/log/td-agent/buffer/td
    use_ssl true
  </store>
</match>

ファイル出力オプションの詳細については、Fluentd Output Optionsを参照してください。

ローカルMongoDBとTreasure Data

以下の設定は、ログをローカルMongoDB ReplicaSetとTreasure Dataに保存する方法を示しています。ログは60秒ごとにMongoDBにフラッシュされます。

<match td.*.*>
  type copy
  <store>
    type mongo_replset
    database td
    collection logs
    nodes localhost:27017,localhost:27018,localhost:27019
  </store>
  <store>
    type tdlog
    endpoint api.treasuredata.com
    apikey YOUR_API_KEY_HERE
    auto_create_table
    buffer_type file
    buffer_path /var/log/td-agent/buffer/td
    use_ssl true
  </store>
</match>

MongoDB出力オプションの詳細については、Fluentd out_mongoを参照してください。認証、capped collection などのさまざまな機能のpluginがあります。

リモートAmazon S3とTreasure Data

以下の設定は、ログをAmazon S3バケットとTreasure Dataの両方に保存する方法を示しています。ログは毎時0分にAmazon S3にフラッシュされます。つまり、最初のアップロードはすぐには開始されません。初回テストを確認するには、次の時間の0分まで待機してください。

<match td.*.*>
  type copy
  <store>
    type s3

    aws_key_id YOUR_AWS_KEY_ID
    aws_sec_key YOUR_AWS_SECRET/KEY
    s3_bucket YOUR_S3_BUCKET_NAME
    path logs/
    buffer_path /var/log/td-agent/buffer/s3

    time_slice_format %Y%m%d-%H
    time_slice_wait 10m
    utc
  </store>
  <store>
    type tdlog
    endpoint api.treasuredata.com
    apikey YOUR_API_KEY_HERE
    auto_create_table
    buffer_type file
    buffer_path /var/log/td-agent/buffer/td
    use_ssl true
  </store>
</match>

S3出力オプションの詳細については、Fluentd S3を参照してください。