Azure CLI for Azure Monitor

The Azure Command Line Interface (Azure CLI) is a set of commands used to create and manage Azure resources. It is available across many Azure services including Azure Monitor. There are over 100 references for Azure Monitor giving you the ability to work effectively with monitor services from a command line.

References for Azure Monitor

The Azure Monitor CLI experience is composed of two parts: Azure CLI (commonly referred to as CLI core) and the Azure Monitor CLI extension. Azure CLI extension references must be installed prior to use. The az extension add command installs an extension reference by name.


Azure Monitor now includes Application Insights and Log Analytics. As such, you must install the extensions for each sub-area when working with Azure Monitor CLI.


Reference Install extension Description For more information see
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 activity-log Manage activity log including activity log alerts. Azure activity logs
az monitor alert DO NOT USE for new development. This command manages older classic metric-based alert rules, which in all but a few cases have been migrated to the newer metric alert types. Use az monitor metrics alert instead.
az monitor app-insights yes Manage Application Insights for application monitoring. Application insights overview
az monitor autoscale Manage autoscale settings. Autoscale overview
az monitor diagnostic-settings Manage service diagnostic settings, which sets up collection and routing of many types of platform metrics and logs. Create diagnostic settings
az monitor log-analytics Manage log clusters and work spaces. Designing your Azure Monitor Logs deployment
az monitor log-analytics query yes Commands for querying data in Log Analytics workspaces. Get started with Log Analytics queries
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 resource. Use Azure Private Link to securely connect networks to Azure Monitor

Installing extension references

Azure CLI extension references must be installed prior to use. The az extension add command installs an extension reference by name.

# install the extension for az monitor app-insights
az extension add --name application-insights

# install the extension for az monitor log-analytics
az extension add --name log-analytics

Azure CLI reference examples

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 single command line. Here are a few code samples to give you an idea of how easy it is to use the Azure CLI.

To work with Azure Monitor, you'll 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

Creating an Azure Monitor log alert is just as straightforward.

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

See also