LoginSignup
0
0

More than 1 year has passed since last update.

ロググループ > ログストリームのDatadog MonitorをTerraformで作成

Last updated at Posted at 2022-07-14

What's This

ログストリーム単位でDatadog MonitorをTerraformコードで作成した時があったので、その時のメモです。
あくまでメモなので、参考にされる場合は、公式ドキュメント等の副読的な感じで読まれると幸いです。

バージョン情報

$ terraform version
Terraform v0.12.0
+ provider.datadog v2.25.0

コード

自分が構築時に気になっていたのは、以下でした。

・クエリをどう書くか
・記載が必須なものは何か

ダウンタイムの設定や、タグの設定、閾値など、ご希望の値に置き換えていただけたらいいのかなと思います。

resource "datadog_monitor" "ec2-error-test" {
  name                = "ec2-error-test"
  new_host_delay      = 0
  no_data_timeframe   = 0
  notify_audit        = false
  notify_no_data      = false
  priority            = 0
  query               = "logs(\"@aws.awslogs.logStream:ec2-error-test\").index(\"*\").rollup(\"count\").by(\"@aws.awslogs.logGroup,@aws.awslogs.logStream\").last(\"5m\") \u003e= 1"
  renotify_interval   = 0
  require_full_window = false
  restricted_roles    = []
  silenced = {
    "*" : 0
  }
  tags              = []
  threshold_windows = null
  thresholds        = null
  timeout_h         = 0
  type              = "log alert"
  validate          = null
  message           = "message"
}

備考①

ちなみに、

\"@aws.awslogs.logStream:ec2-error-test\"

についてですが、ここのログストリームの指定は、AWSで作成していないログストリームも指定することができます。

備考②

ちなみに、

\"@aws.awslogs.logStream:ec2-error-test 検知したい文字列\"

とすることで、ログストリームec2-error-test内で、検知したい文字列が発生した場合、それのみを検知するモニターにすることができます。

検知したい文字列:crit
スクリーンショット 2022-07-13 16.18.24.png

検知したい文字列:emerg
スクリーンショット 2022-07-13 16.18.37.png

Reference

https://docs.datadoghq.com/ja/logs/logs_to_metrics/
https://www.datadoghq.com/ja/blog/amazon-cloudwatch-metric-streams-datadog/
https://registry.terraform.io/providers/DataDog/datadog/latest/docs/resources/monitor

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