【问题标题】:Terraform Google provider, create log-based alerting policyTerraform Google 提供商,创建基于日志的警报策略
【发布时间】:2021-10-26 12:51:15
【问题描述】:

我需要通过 Terraform Google 云提供商创建基于日志的警报策略: https://cloud.google.com/logging/docs/alerting/monitoring-logs#lba

我查看了 Terraform 官方文档,看到了“google_monitoring_alert_policy”资源:https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/monitoring_alert_policy

我没有在此文档中找到如何创建基于日志的警报策略。
我可以创建“指标”类型但不能使用“日志”类型的警报策略

我使用最新版本的 Terraform 谷歌云提供商:https://registry.terraform.io/providers/hashicorp/google/latest

请问如何使用 Terraform Google 提供商创建基于日志的警报策略?

提前感谢您的帮助。

【问题讨论】:

标签: google-cloud-platform terraform terraform-provider-gcp google-cloud-monitoring


【解决方案1】:

谢谢纪尧姆。

是的,这就是我解决问题的方式。

现在无法通过 Terraform 直接创建具有“日志”类型的警报。

解决这个问题的步骤:

  • 使用预期过滤器创建基于日志的指标
  • 根据之前创建的基于日志的指标创建类型为“指标”的警报策略
resource "google_logging_metric" "my_log_metrics" {
  project = var.project_id
  name = "my-log-metric"
  filter = "..."
  description = "..."
  metric_descriptor {
    metric_kind = "..."
    value_type = "..."
  }
}

resource "google_monitoring_alert_policy" "my_policy" {
  project = var.project_id
  display_name = "my-policy"
  combiner = "OR"
  conditions {
    display_name = "my-policy"
    condition_threshold {
      filter = "metric.type=\"logging.googleapis.com/user/my-log-metric\" AND resource.type=\"cloud_composer_environment\""
    ...
    }
}

【讨论】:

  • 嗨 Mazlum,你为 metric_kind 和 value_type 设置了什么值?
  • 嗨,Richard,例如,在我的情况下,我想增加指标并在每次云日志记录中出现该模式时发送警报。在这种情况下,您可以设置以下参数:“metric_kind”:“DELTA”,“value_type”:“INT64”,
  • 您好 Mazlum,非常感谢。
【解决方案2】:

格式为logging.googleapis.com/user/<user metrics name>

看这个例子(没有通知,只有警报策略)

resource "google_monitoring_alert_policy" "alert_policy" {
  display_name = "My Alert Policy"
  combiner     = "OR"
  conditions {
    display_name = "test condition"
    condition_threshold {
      filter     = "metric.type=\"logging.googleapis.com/user/test-metrics\" AND resource.type=\"cloud_run_revision\""
      duration   = "600s"
      comparison = "COMPARISON_GT"
      threshold_value = 1
      }
    }

  user_labels = {
    foo = "bar"
  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-12
    • 1970-01-01
    • 2021-09-14
    • 2021-09-29
    • 2019-01-26
    • 2021-05-28
    相关资源
    最近更新 更多