vague memory

うろ覚えを無くしていこうともがき苦しむ人の備忘録

Datadog dogstream 注意点

ログ管理機能 ( Introducing logs in Datadog ) のリリースが控えていますが、地味にハマったので今更ながら dogstream での注意点を残しておきます。
ちなみにログ管理機能が含まれる予定の Agent version >= 6.0 からはパラメータ自体廃止されているようなので、6.0以降は機能が無くなるようです。
(カスタムメトリクスは DogStatsD 等の別手法で送信した方が良さそうです)



dogstream とは

ファイルに出力された値をメトリクスとして送信する機能です。

有効化

datadog.conf 内の dogstreams へ対象ログファイルを設定します。

dogstreams: /var/log/web.log, /var/log/db.log, /var/log/cache.log

公式ログフォーマット

metric unix_timestamp value [attribute1=v1 attributes2=v2 ...]

上記フォーマットに合致しないログについては、カスタムパーサを用意することで対応します。

注意点

本題です。 公式ドキュメントに記載はありますが、英語ページのみです。日本語ページには記載がありません。

A word of warning:
there is a limit to how many times the same metric can be collected in the same log-pass;
effectively the agent starts to over-write logged metrics with the subsequent submissions of the same metric,
even if they have different attributes (like tags).
This can be somewhat mitigated if the metrics collected from the logs have sufficiently different time-stamps,
but it is generally recommended to only submit one metric to the logs for collection once every 10 seconds or so.
This over-writing is not an issue for metrics collected with differing names.

同一ファイル内の同一メトリクス名での送信は値が上書かれる可能性があります。

以下のような形式でファイルへ出力していたとします。

# metric        unix_timestamp    value  attribute1           attribute2 attribute3
# ---------
publish_time    1514605081        593    metric_type=gauge    unit=ms    stage=prd
publish_time    1514605081        799    metric_type=gauge    unit=ms    stage=stg
publish_time    1514605083        693    metric_type=gauge    unit=ms    stage=stg
publish_time    1514605111        553    metric_type=gauge    unit=ms    stage=prd
publish_time    1514605111        588    metric_type=gauge    unit=ms    stage=stg
・・・

メトリクス名 publish_time とし、stageタグで系列分けが行えるようにします。 Datadog上での表示は以下のようになります。

f:id:htnosm:20180108015941p:plain

上書きが発生する場合

stage=prd の後に stage=stg が出力されているため、後者の値で上書きが発生します。 Datadog側に Datapoint として存在せず、送信できていないかのように見えます。

f:id:htnosm:20180108015954p:plain

公式ドキュメントによると10秒間に一度は出力する事が推奨とあります。 実際に、短時間(数秒)で出力されるログでは発生頻度は低かったですが、数十秒間隔の出力になるとほぼほぼ上書きが発生していました。

回避策

以下いずれかで回避可能です。

  • a) 数秒間隔で出力する
    • 上書きされる頻度は下がる
  • b) メトリクス名を分ける
    • グラフ作成時に複数メトリクス指定が必要になるので、属性(attribute)が増えてくると利用し難い
  • c) 出力ファイルを分ける
    • datadog.conf へ複数ファイル指定が必要