Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
This article shows you sample command-line interface (CLI) commands to help you access Azure Monitor features. Azure Monitor allows you to AutoScale Cloud Services, Virtual Machines, and Web Apps and to send alert notifications or call web URLs based on values of configured telemetry data.
If you haven't already installed the Azure CLI, follow the instructions for Install the Azure CLI. See a full reference of all available commands in the Azure Monitor CLI reference.
The first step is to log in to your Azure account.
az login
After running this command, you have to sign in via the instructions on the screen. All commands work in the context of your default subscription.
List the details of your current subscription.
az account show
Change working context to a different subscription.
az account set -s <Subscription ID or name>
View a list of all supported Azure Monitor commands.
az monitor -h
View a list of activity log events.
az monitor activity-log list
View all available options.
az monitor activity-log list -h
List logs by a resourceGroup.
az monitor activity-log list --resource-group <group name>
List logs by caller.
az monitor activity-log list --caller myname@company.com
List logs by caller on a resource type, within a date range.
az monitor activity-log list --resource-provider Microsoft.Web \
--caller myname@company.com \
--start-time 2016-03-08T00:00:00Z \
--end-time 2016-03-16T00:00:00Z
Note
Only alerts (classic) is supported in CLI at this time.
az monitor activity-log alert list --resource-group <group name>
az monitor activity-log alert show --resource-group <group name> --name <alert name>
az monitor alert create --name <alert name> --resource-group <group name> \
--action email <email1 email2 ...> \
--action webhook <URI> \
--target <target object ID> \
--condition "<METRIC> {>,>=,<,<=} <THRESHOLD> {avg,min,max,total,last} ##h##m##s"
az monitor alert delete --name <alert name> --resource-group <group name>
Use the information in this section to work with log profiles.
az monitor log-profiles list
az monitor log-profiles show --name <profile name>
az monitor log-profiles create --name <profile name> --location <location of profile> \
--locations <locations to monitor activity in: location1 location2 ...> \
--categories <categoryName1 categoryName2 ...> \
--days <# days to retain> \
--enabled true \
--storage-account-id <storage account ID to store the logs in>
az monitor log-profiles create --name <profile name> --location <location of profile> \
--locations <locations to monitor activity in: location1 location2 ...> \
--categories <categoryName1 categoryName2 ...> \
--days <# days to retain> \
--enabled true
--storage-account-id <storage account ID to store the logs in>
--service-bus-rule-id <service bus rule ID to stream to>
az monitor log-profiles delete --name <profile name>
Use the information in this section to work with diagnostic settings.
az monitor diagnostic-settings list --resource <target resource ID>
az monitor diagnostic-settings create --name <diagnostic name> \
--storage-account <storage account ID> \
--resource <target resource object ID> \
--logs '[
{
"category": <category name>,
"enabled": true,
"retentionPolicy": {
"days": <# days to retain>,
"enabled": true
}
}]'
az monitor diagnostic-settings delete --name <diagnostic name> \
--resource <target resource ID>
Use the information in this section to work with autoscale settings. You need to modify these examples.
az monitor autoscale list --resource-group <group name>
az monitor autoscale show --name <settings name> --resource-group <group name>
az monitor autoscale create --name <settings name> --resource-group <group name> \
--count <# instances> \
--resource <target resource ID>