Management
Metric alert
Evaluates metric conditions and can notify action groups when a threshold is crossed.
Naming rules
- Abbreviation
- Length
- 1-260
- Allowed characters
- Can't use: *#&+:<>?@%{}\/| or control characters Can't end with space or period.
- Uniqueness scope
- resource group
Azure Verified Modules naming utility v0.3.0 · AVM naming key metric_alert
Code examples
Adapt the examples to your environment and supply referenced resources and variables.
Terraform
Terraform documentationhcl
terraform {
required_providers {
azapi = {
source = "Azure/azapi"
version = "~> 2.0"
}
}
}
variable "actionGroupId" {
type = string
}
variable "name" {
type = string
}
variable "virtualMachineId" {
type = string
}
variable "parent_id" {
description = "Full Azure resource ID of the parent resource or resource group."
type = string
}
resource "azapi_resource" "example" {
type = "Microsoft.Insights/metricAlerts@2026-01-01"
name = var.name
parent_id = var.parent_id
location = "global"
body = {
properties = {
description = "Alert on sustained high CPU for one VM."
severity = 2
enabled = true
scopes = [
var.virtualMachineId
]
evaluationFrequency = "PT5M"
windowSize = "PT15M"
criteria = {
"odata.type" = "Microsoft.Azure.Monitor.SingleResourceMultipleMetricCriteria"
allOf = [
{
criterionType = "StaticThresholdCriterion"
name = "highCpu"
metricNamespace = "Microsoft.Compute/virtualMachines"
metricName = "Percentage CPU"
operator = "GreaterThan"
threshold = 90
timeAggregation = "Average"
}
]
}
actions = [
{
actionGroupId = var.actionGroupId
}
]
}
}
}
Bicep
Bicep documentationbicep
param actionGroupId string
param name string
param virtualMachineId string
resource example 'Microsoft.Insights/metricAlerts@2026-01-01' = {
name: name
location: 'global'
properties: {
description: 'Alert on sustained high CPU for one VM.'
severity: 2
enabled: true
scopes: [
virtualMachineId
]
evaluationFrequency: 'PT5M'
windowSize: 'PT15M'
criteria: {
'odata.type': 'Microsoft.Azure.Monitor.SingleResourceMultipleMetricCriteria'
allOf: [
{
criterionType: 'StaticThresholdCriterion'
name: 'highCpu'
metricNamespace: 'Microsoft.Compute/virtualMachines'
metricName: 'Percentage CPU'
operator: 'GreaterThan'
threshold: 90
timeAggregation: 'Average'
}
]
}
actions: [
{
actionGroupId: actionGroupId
}
]
}
}
ARM template
ARM template documentationjson
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"actionGroupId": {
"type": "string"
},
"name": {
"type": "string"
},
"virtualMachineId": {
"type": "string"
}
},
"resources": [
{
"type": "Microsoft.Insights/metricAlerts",
"apiVersion": "2026-01-01",
"name": "[parameters('name')]",
"location": "global",
"properties": {
"description": "Alert on sustained high CPU for one VM.",
"severity": 2,
"enabled": true,
"scopes": [
"[parameters('virtualMachineId')]"
],
"evaluationFrequency": "PT5M",
"windowSize": "PT15M",
"criteria": {
"odata.type": "Microsoft.Azure.Monitor.SingleResourceMultipleMetricCriteria",
"allOf": [
{
"criterionType": "StaticThresholdCriterion",
"name": "highCpu",
"metricNamespace": "Microsoft.Compute/virtualMachines",
"metricName": "Percentage CPU",
"operator": "GreaterThan",
"threshold": 90,
"timeAggregation": "Average"
}
]
},
"actions": [
{
"actionGroupId": "[parameters('actionGroupId')]"
}
]
}
}
]
}