LoginSignup
1
0

More than 1 year has passed since last update.

Datadogによるfluentdのログ転送状況の監視

Posted at

概要

fluentdを使用して、AWS上のEC2インスタンスからS3へログ転送を実施している。
今回、ログ転送状況の監視(転送遅延の発生有無)を行う要件が発生した。

この要件に対し、SaaSベースの監視ソリューション、Datadogを利用して、Fluentdの以下の項目を監視することで対応を行なった。

  • bufferに滞留しているqueueの数
  • データ転送リトライの数

fluentdによるログ転送が遅延している状態とは?

まず、監視を行う前に、fluentdのログ転送に関連するメトリクスを整理すると以下になる。

  • fluentdのキュー関連のパラメーター値
メトリクス デフォルト値
buffer_queue_limit 256(個)
buffer_chunk_limit 8(MB)
retry_limit 17(回)

*上記はデフォルト値であり、実際の値はプロジェクトにより異なる。

  • Datadogで取得できるfluentdのMetrics
    flunetndの標準プラグインin_monitor_agentを有効化することで取得できるバッファーに関するMetrics
メトリクス 概要 値が増えた時の影響
buffer_queue_length バッファーに蓄積されているキューの数 buffer_queue_limitで設定した値を超えるとログデータがロストする
buffer_total_queued_size バッファーに蓄積されているキューの合計サイズ buffer_queue_limit × buffer_chunk_limitの値を超えるとログデータがロストする
retry_count データ再送を試みた回数 retry_limitで設定した回数を超えるとバッファーがリセットされる

次に、上記を踏まえ監視対象のメトリクスと閾値を策定した。
(閾値は検討の結果を反映)

監視項目 閾値
bufferに滞留しているqueueの数 205 (buffer_queue_limit値の80%)
データ転送リトライの数 12 (再送開始から1時間超過前のretry_limitの数)

*buffer_total_queued_sizeについては、先にbuffer_queue_limitが閾値に達するので、監視対象外とする。

*retry実施回数と要する時間については、参考情報の"Fluentdの障害時動作"を参照

設定内容

以下、設定した内容を記載する。

fluentd

  • monitor_agentの有効化の実施
    /etc/td-agent/td-agent.conf に以下のエントリーを追加する。
/etc/td-agent/td-agent.conf
<source>

  @type monitor_agent

  port 24220

</source>

Datadog Agent

  • fluentdのメトリクスの収集設定の追加
    /etc/datadog-agent/conf.d/fluentd.d/fluentd.yaml 内のエントリーを以下のように修正する。
/etc/datadog-agent/conf.d/fluentd.d/fluentd.yaml
init_config:

instances:

  # Every instance requires a `monitor_agent_url`
  # Optional, set `plugin_ids` to monitor a specific scope of plugins.
  #-  monitor_agent_url: http://example.com:24220/api/plugins.json
  #   plugin_ids:
  #     - plg1
  #     - plg2
  #   tags:
  #     - 'test'
  #     - 'datacenter:northeast'
  # Optional, set 'tag_by' to specify how to tag metrics. By default, metrics are tagged with `plugin_id`
  -  monitor_agent_url: http://localhost:24220/api/plugins.json
     tag_by: type

Datadog コンソール

  • fluentd - Buffer queue length (chunks) のモニター設定

Query
avg(last_5m):max:fluentd.buffer_queue_length{type:s3,environment:prd} by {host} > 205

** Query内の205は今回の閾値

  • fluentd - Retry count 通知 のモニター設定

Query
avg(last_5m):max:fluentd.retry_count{type:s3,environment:prd} by {host} > 11

** Query内の11は今回の閾値

参考にした情報

monitor-agentの監視スクリプトをつくった

Fluentdの監視

fluentdの効果的な活用例と安定運用のポイント

Fluentdの障害時動作

1
0
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
1
0