Azure CLI reference commands for Azure Monitor

The Azure Command-Line Interface (CLI) is a set of commands used to create and manage Azure resources for many Azure services. For Azure Monitor, over 100 different commands are available, which give you the ability to work effectively with the service from a command-line.

The Azure CLI commands for Azure Monitor are composed of two parts: Azure CLI (commonly referred to as CLI core) and the Azure Monitor CLI footprint extension. The Azure CLI extension for Azure Monitor is automatically installed the first time you run the extension reference. For more information about extension references, see Use extensions with Azure CLI.

Important

Azure Monitor now includes Application Insights and Log Analytics. You must install the extensions for each sub-area when working with the Azure CLI for Azure Monitor. You're prompted to install an extension reference on first use. Or, you can use the az extension add command to manually install an extension.

Azure Monitor references

List of Azure CLI references that can be used to manage Azure Monitor, reference descriptions, and links to popular articles:

Reference Install extension Description For more information
az monitor The top-level command group for all Azure CLI commands for Azure Monitor. Azure Monitor overview
az monitor action-group Manage action groups, which relate to notifications once an alert has fired. Azure Monitor alerts
az monitor action-rule yes Manage action rules, which let you add or suppress the action groups on your fired alerts. Azure Monitor alerts
az monitor activity-log Manage activity logs, including activity log alerts. Azure activity logs
az monitor app-insights yes Manage Application Insights for application monitoring. Application insights overview
az monitor autoscale Manage autoscale settings. Autoscale overview
az monitor data-collection yes Manage data collection rules. Data collection rules
az monitor diagnostic-settings Manage service diagnostic settings, which set up collection and routing of many types of platform metrics and logs. Create diagnostic settings
az footprint yes Manage Azure Footprint settings.
az monitor log-analytics Manage log clusters and work spaces. Designing your Azure Monitor Logs deployment
az monitor log-analytics solution yes Manage Log Analytics solutions.
az monitor log-profiles DO NOT USE for new development. This command was previously used to route activity logs to Azure Monitor Logs and Log Analytics. Use diagnostic settings instead. Send the Activity log to a Log Analytics workspace
az monitor metrics Manage platform metrics and near-realtime metric alert rules. Overview of metrics in Azure Monitor and Understand how metric alerts work
az monitor private-link-scope Manage monitor private link scope resources. Use Azure Private Link to securely connect networks to Azure Monitor
az monitor scheduled-query yes Manage scheduled queries.

Azure CLI reference examples for Azure Monitor

Examples are provided with every Azure CLI reference. Although you can also complete these tasks through the Azure portal, using the Azure CLI requires a command line. Here are a few code blocks to give you an idea of how easy it is to use the Azure CLI.

To work with Azure Monitor, you first need a resource group. Azure resource groups are simple to create and manage with the Azure CLI.

#create a resource group
az group create --location westus --name MyResourceGroup

#get a list of resource groups for a subscription
az group list --subscription MySubscription --output table

It's also easy to create an Azure Monitor log alert.

#create an Azure Monitor activity log alert
az monitor activity-log alert create --name MyAlertName --resource-group MyResourceGroup

See also