How do I configure an Azure monitoring metric alert?
This guide demonstrates how to create a metric alert in Azure to monitor specific metrics, such as CPU usage, using best practices for defining the alert conditions and action groups. The example illustrates defining a metric alert that triggers when a certain condition is met and specifying the notification settings.
What We’re Doing:
- Creating a resource group where all resources will reside.
- Creating an Action Group that will define the notification settings.
- Configuring a Metric Alert that triggers based on a defined condition.
import * as pulumi from "@pulumi/pulumi";
import * as azure from "@pulumi/azure";
// Create Resource Group
const example = new azure.core.ResourceGroup("example", {
name: "example-resources",
location: "West Europe",
});
// Create Action Group
const exampleActionGroup = new azure.monitoring.ActionGroup("example", {
name: "example-action-group",
resourceGroupName: example.name,
shortName: "example-ag",
emailReceivers: [{
name: "sendtoadmin",
emailAddress: "admin@example.com",
}],
smsReceivers: [{
name: "sendtoadmin_sms",
countryCode: "1",
phoneNumber: "1234567890",
}],
});
// Create Metric Alert
const exampleMetricAlert = new azure.monitoring.MetricAlert("example", {
name: "example-metric-alert",
resourceGroupName: example.name,
scopes: [example.id],
description: "Example metric alert for demonstration",
severity: 2,
frequency: "PT1M",
windowSize: "PT5M",
criterias: [{
metricNamespace: "Microsoft.Compute/virtualMachines",
metricName: "Percentage CPU",
aggregation: "Total",
operator: "GreaterThan",
threshold: 80,
}],
actions: [{
actionGroupId: exampleActionGroup.id,
}],
tags: {
environment: "demo",
},
});
export const resourceGroupId = example.id;
export const metricAlertId = exampleMetricAlert.id;
Key Points:
- Resource Group: Organize and manage related resources.
- Action Group: Defines who gets notified and how.
- Metric Alert: Specifies the conditions that trigger the alert and the associated actions.
Summary
We’ve successfully set up an Azure Metric Alert within a defined Resource Group. The alert is hooked up to an Action Group, which lets us handle notifications via email and SMS when specific metric conditions are met. This setup is crucial for proactive monitoring and management of Azure resources.
Deploy this code
Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.
Sign upNew to Pulumi?
Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.
Sign upThank you for your feedback!
If you have a question about how to use Pulumi, reach out in Community Slack.
Open an issue on GitHub to report a problem or suggest an improvement.