简体   繁体   中英

Azure CLI monitor metrics of all virtual machines

I want to monitor metrics of all virtual machines inside my subscription with Azure CLI. According to Microsoft's "az monitor metrics alert" documentation, each alert created for a specific resource id, for example:

az monitor metrics alert create -n alert1 -g {ResourceGroup} --scopes {VirtualMachineID} --condition "avg Percentage CPU > 90" --description "High CPU"

Can I create an alert for monitoring high CPU for all VMs (instead of creating many alerts associated with a specific VM)? Moreover, how can I configure my email as an alert action?

Thank you.

From the syntax, it seems like if we just pass a comma-separated list of Resource IDs to --scope parameter we should be able to create a metrics alert for multiple resources. But it doesn't seem to work as expected.

As an alternative, you can configure an ARM Template to create Azure Monitor Metrics alert that can target/monitor multiple resources in one or more Resource Groups, or in a Subscription.

You can refer this documentation on how to build ARM Templates for a Metric alert that monitors multiple resources.

In this template, you'll need to provide the Action Group ID for the Action Group which specifies the actions to be taken when the alert triggers. To obtain the Action Group ID, use Set-AzActionGroup to create an Action Group wherein you can specify the action to receive email in the -Receiver parameter.

Once you've configured your template & template parameters JSON file, you can use the following Az CLI cmdlet block to deploy it in Azure:

Connect-AzAccount
Select-AzSubscription -SubscriptionName <yourSubscriptionName>
New-AzResourceGroupDeployment -Name myDeployment -ResourceGroupName <ResourceGroupWhereRuleShouldbeSaved> -TemplateFile template.json -TemplateParameterFile templateparams.parameters.json

Hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM