1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

terraformでsynthetics_monitorを作成する方法

Posted at

はじめに

Terraformでsynthetics_monitorを作成したのでメモしてみました!

今回編集するファイル

variable.tf
condition-synthetics_monitor.tf
policy.tf

手順

variable.tf.で変数の定義

variable "synthetics_monitor" {
  type = map(string)
  default = {
    # URL
    # Key:synthetics_statuscode
    # Value:https://aaaa.aaaa.jp
    synthetics_statuscode       = "https://*****.*****.jp"
  }
}

condition-synthetics_monitor.tfにsynthetics_monitorを記載

# -----------------------------
# # Syntheticsの設定
# -----------------------------
resource "newrelic_synthetics_monitor" "synthetics_statuscode" {  #"リソースの指定でnewrelicのモニターを指定、teraform内の設定で一意になる名前"
  status           = "ENABLED" # モニタのステータス("ENABLED" または "DISABLED")
  name             = "monitor" # monitorのタイトル
  period           = "EVERY_MINUTE" #モニタの実行頻度
  uri              = var.synthetics_monitor.synthetics_statuscode #monitorの対象となるURL
  type             = "SIMPLE" #Syntheticsモニタの種類を指定(SIMPLE / BROWSER / SCRIPT_BROWSER / SCRIPT_API)
  locations_public = ["AP_NORTHEAST_1"] #モニタの実行地域
}
# -----------------------------
# # Conditionの設定
# -----------------------------
resource "newrelic_nrql_alert_condition" "synthetics_statuscode" {
  policy_id   = newrelic_alert_policy.alert_policy.id
  name        = "外形監視"

  violation_time_limit_seconds = 3600
  aggregation_window           = 600
  aggregation_timer            = 60
  aggregation_method           = "event_timer"
  slide_by                     = 60

  nrql {
    query = "SELECT count(*) FROM SyntheticCheck FACET monitorName, location, result WHERE result = 'FAILED' AND monitorName IN ('${var.synthetics_monitor.synthetics_statuscode}')"
  }

  critical {
    operator              = "above"
    threshold             = 9
    threshold_duration    = 600
    threshold_occurrences = "all"
  }
}

policy.tfにポリシーの設定

resource "newrelic_alert_policy" "alert_policy" {
  name                = var.project_name
  incident_preference = "PER_CONDITION_AND_TARGET" #ポリシー内のconditionを個別に検知してくれて、異なるインシデントとして扱うことができる。
}

参考

https://registry.terraform.io/providers/newrelic/newrelic/latest/docs/resources/synthetics_monitor
https://registry.terraform.io/providers/newrelic/newrelic/latest/docs/resources/nrql_alert_condition

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?