I am trying to deploy Memory metric which comes under guest metrics for a VM using Terraform, I have already defined namespace for the metric that I am using but its throwing below error.
Error creating or updating metric alert "Memory Usage Alert" (resource group "MyTemp"): insights.MetricAlertsClient#CreateOrUpdate: Failure responding to request: StatusCode=400 -- Original Error: autorest/azure: Service returned an error. Status=400 Code="BadRequest" Message="The following metric name(s) were not found: Memory\% Committed bytes in use. Please note that for custom metrics, the relevant metric namespace must be specified.
resource "azurerm_monitor_metric_alert" "myalert" {
name = "Memory Usage Alert"
resource_group_name = var.rg_name //resource name to which you want to deploy this alert
scopes = [var.virtual_machine_id]
description = "Action will be triggered when Memory Utilzation count is greater than 85."
target_resource_type = "Microsoft.Compute/virtualMachines"
target_resource_location = "centralindia"
frequency = "PT30M"
window_size = "P1D"
severity = "2"
enabled = "true"
criteria {
metric_namespace = "azure.vm.windows.guestmetrics"
metric_name = "Memory\\% Committed bytes in use"
aggregation = "Average"
operator = "GreaterThanOrEqual"
threshold = 85
}
action {
action_group_id = var.action_name
}
}
Regarding the issue, you can refer to the following script
Please note that before running the script, you need to enable Azure MSI and boot_diagnostics in your VM