【问题标题】:create 2 criteria in an alert that monitors multiple criteria in terraform (azure)在监视 terraform 中的多个条件的警报中创建 2 个条件(天蓝色)
【发布时间】:2021-11-30 13:11:35
【问题描述】:

我想添加另一个条件,但出现此错误 当警报规则包含多个条件时,维度的使用仅限于每个条件内每个维度一个值

resource "azurerm_monitor_metric_alert" "example" {
     name                = "example-metricalert"
     resource_group_name = azurerm_resource_group.main.name
     scopes              = [azurerm_storage_account.to_monitor.id]
     description         = "Action will be triggered when Transactions count is greater than 50."

    criteria {
       metric_namespace = "Microsoft.Storage/storageAccounts"
       metric_name      = "Transactions"
       aggregation      = "Total"
       operator         = "GreaterThan"
       threshold        = 50

    dimension {
      name     = "ApiName"
      operator = "Include"
      values   = ["*"]
      }
        }
  
    criteria {
       metric_namespace = "Microsoft.Storage/storageAccounts"
       metric_name      = "Transactions"
       aggregation      = "Total"
       operator         = "GreaterThan"
       threshold        = 50

    dimension {
      name     = "ApiName"
      operator = "Include"
      values   = ["*"]
    }
       }

      action {
         action_group_id = azurerm_monitor_action_group.main.id
        }

【问题讨论】:

  • 您好@Mr_Unchanied,AFAIK 如果有多个维度,即维度值不能为 ["*"],则无法创建另一个条件/标准。如果您可以在那里提供特定的 API 名称,那么您可以创建另一个标准。门户网站也一样

标签: azure cloud devops terraform-provider-azure infrastructure


【解决方案1】:

当您为一个条件设置多个维度时,您不能为警报规则设置两个条件,即您不能将维度值用作["*"]

如果您希望在一个指标警报中包含多个条件,那么您必须为一个条件提供一些维度值,并为其他条件提供相同的维度,或者您也不能同时为这两个条件使用维度块。

例如,您可以参考以下代码:

resource "azurerm_monitor_metric_alert" "example" {
  name                = "example-metricalert"
  resource_group_name = azurerm_resource_group.main.name
  scopes              = [azurerm_storage_account.to_monitor.id]
  description         = "Action will be triggered when Transactions count is greater than 50."

  criteria {
    metric_namespace = "Microsoft.Storage/storageAccounts"
    metric_name      = "Transactions"
    aggregation      = "Total"
    operator         = "GreaterThan"
    threshold        = 50

    dimension {
      name     = "ApiName"
      operator = "Include"
      values   = ["GetBlobServiceProperties"]

    }
  }
criteria {
    metric_namespace = "Microsoft.Storage/storageAccounts"
    metric_name      = "SuccessE2ELatency"
    aggregation      = "Average"
    operator         = "GreaterThan"
    threshold        = 10
        dimension {
      name     = "ApiName"
      operator = "Include"
      values   = ["GetBlobServiceProperties"]

    }
  }


  action {
    action_group_id = azurerm_monitor_action_group.main.id
  }
}

resource "azurerm_monitor_metric_alert" "example1" {
  name                = "example1-metricalert"
  resource_group_name = azurerm_resource_group.main.name
  scopes              = [azurerm_storage_account.to_monitor.id]
  description         = "Action will be triggered when Transactions count is greater than 50."

  criteria {
    metric_namespace = "Microsoft.Storage/storageAccounts"
    metric_name      = "Transactions"
    aggregation      = "Total"
    operator         = "GreaterThan"
    threshold        = 50
  }
criteria {
    metric_namespace = "Microsoft.Storage/storageAccounts"
    metric_name      = "SuccessE2ELatency"
    aggregation      = "Average"
    operator         = "GreaterThan"
    threshold        = 10
  }


  action {
    action_group_id = azurerm_monitor_action_group.main.id
  }
}

【讨论】:

  • 感谢您的解释
猜你喜欢
  • 2022-01-11
  • 2021-11-01
  • 2021-09-29
  • 1970-01-01
  • 2021-03-29
  • 2020-07-16
  • 1970-01-01
  • 2021-08-03
  • 2021-06-05
相关资源
最近更新 更多