0
resource "azurerm_monitor_metric_alert" "exception_alert_test_incoming_orders" {
  name                = "IncomingOrderTest"
  resource_group_name = "${var.azurerm_resource_group_name}"
  scopes              = ["${azurerm_application_insights.app_insights_test.id}"]

  enabled = "${var.test_insight_alerts_enabled}"

  description = "Alert due to 0 incoming orders on last 24 hours (Test)"

  frequency = "PT1H"

  window_size = "P1D"

  criteria {
    metric_namespace = "Azure.ApplicationInsights"
    metric_name      = "IncomingOrder"
    aggregation      = "Count"
    operator         = "Equals"
    threshold        = 0

  }

  action {
    action_group_id = "${azurerm_monitor_action_group.monitor_alert_action_test.id}"
  }
}

The alerts are not getting trigerred the variables are correct , and not sure about the metric_namespace.

Anas Ali
  • 67
  • 1
  • 3

2 Answers2

0

metric_namespace needs to represent the azure resource type.

For example: "Microsoft.Storage/storageAccounts" as this is where the metric for the alert is to be generated.

I believe for application insight alerts the metric_namespace ismicrosoft.insights/components.

Everything else looks good!

Lachie White
  • 1,246
  • 2
  • 14
  • 21
  • "Microsoft.Insights/Components" namespace only seem to support predefined metrics and not custom metrics. I am getting error metric name not found when trying to use custom metric. https://learn.microsoft.com/en-us/azure/azure-monitor/platform/metrics-supported#microsoftinsightscomponents – Tushar Kesare Feb 13 '20 at 11:23
0

It appears that you need to use monitor_scheduled_query_rules_alert to monitor and alert on custom metrics.

Erik Erikson
  • 418
  • 4
  • 9