0
0
AzureHow-ToBeginner · 4 min read

How to View Metrics in Azure Monitor: Step-by-Step Guide

To view metrics in Azure Monitor, open the Azure portal, navigate to your resource, and select the Metrics option. Then, choose the metric namespace, metric, and time range to see visual charts and data for your resource's performance.
📐

Syntax

Viewing metrics in Azure Monitor involves selecting the resource and specifying the metric parameters.

  • Resource: The Azure service or resource you want to monitor.
  • Metric Namespace: The category grouping related metrics.
  • Metric: The specific measurement you want to view, like CPU usage or network traffic.
  • Time Range: The period for which you want to see the data.
bash
az monitor metrics list --resource /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName} --metric "{metricName}" --interval PT1H --aggregation Average
💻

Example

This example shows how to use the Azure CLI to view the average CPU percentage metric for a virtual machine over the last hour.

bash
az monitor metrics list --resource /subscriptions/12345678-1234-1234-1234-123456789abc/resourceGroups/MyResourceGroup/providers/Microsoft.Compute/virtualMachines/MyVM --metric "Percentage CPU" --interval PT1H --aggregation Average
Output
[ { "id": "/subscriptions/12345678-1234-1234-1234-123456789abc/resourceGroups/MyResourceGroup/providers/Microsoft.Compute/virtualMachines/MyVM/providers/microsoft.insights/metrics/Percentage CPU", "type": "Microsoft.Insights/metrics", "name": { "value": "Percentage CPU", "localizedValue": "Percentage CPU" }, "timeseries": [ { "data": [ { "timeStamp": "2024-06-01T10:00:00Z", "average": 15.3 }, { "timeStamp": "2024-06-01T11:00:00Z", "average": 18.7 } ] } ] } ]
⚠️

Common Pitfalls

Common mistakes when viewing metrics in Azure Monitor include:

  • Not selecting the correct resource path, which leads to no data or errors.
  • Choosing a metric name that does not exist for the resource.
  • Using an incorrect time interval format or aggregation type.
  • Not having proper permissions to read metrics for the resource.

Always verify the resource ID and metric names in the Azure portal or documentation before querying.

bash
az monitor metrics list --resource /subscriptions/12345678/resourceGroups/MyResourceGroup/providers/Microsoft.Compute/virtualMachines/MyVM --metric "CpuUsage" --interval PT1H --aggregation Average

# Wrong metric name 'CpuUsage' instead of 'Percentage CPU'

# Corrected command:
az monitor metrics list --resource /subscriptions/12345678/resourceGroups/MyResourceGroup/providers/Microsoft.Compute/virtualMachines/MyVM --metric "Percentage CPU" --interval PT1H --aggregation Average
📊

Quick Reference

Tips for viewing metrics in Azure Monitor:

  • Use the Azure portal for an easy visual interface.
  • Use Azure CLI or REST API for automation and scripting.
  • Check metric namespaces and available metrics per resource type.
  • Set appropriate time ranges and aggregation types for meaningful data.
  • Ensure you have Reader or higher role permissions on the resource.

Key Takeaways

Open the Azure portal and select your resource to view metrics visually.
Use Azure CLI with the correct resource ID and metric name to fetch metrics programmatically.
Always verify metric names and namespaces to avoid errors.
Set proper time intervals and aggregation types for accurate metric data.
Ensure you have the necessary permissions to access metrics.