0
0
Azurecloud~5 mins

Why monitoring is essential in Azure - Why It Works

Choose your learning style9 modes available
Introduction
Monitoring helps you keep an eye on your cloud services and infrastructure. It shows you if things are working well or if there are problems that need fixing quickly.
When you want to know if your website is up and running without waiting for users to complain
When you need to track how much memory or CPU your app is using to avoid crashes
When you want to get alerts if your database is slow or unreachable
When you want to see trends over time to plan for more resources before problems happen
When you want to improve your app by understanding how users interact with it
Commands
This command checks the CPU usage of a virtual machine every minute to see how busy it is.
Terminal
az monitor metrics list --resource /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM --metric Percentage CPU --interval PT1M
Expected OutputExpected
[ { "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM/providers/microsoft.insights/metrics/Percentage CPU", "type": "Microsoft.Insights/metrics", "name": "Percentage CPU", "unit": "Percent", "timeseries": [ { "data": [ {"timeStamp": "2024-06-01T12:00:00Z", "average": 15.5}, {"timeStamp": "2024-06-01T12:01:00Z", "average": 20.3} ] } ] } ]
--resource - Specifies the exact resource to monitor
--metric - Chooses which performance metric to check
--interval - Sets how often to check the metric
This command creates an alert that notifies you if the CPU usage goes above 80%, so you can fix problems fast.
Terminal
az monitor metrics alert create --name HighCPUAlert --resource-group myResourceGroup --scopes /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM --condition "avg Percentage CPU > 80" --description "Alert when CPU usage is over 80%" --action-group myActionGroup
Expected OutputExpected
{ "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/microsoft.insights/metricAlerts/HighCPUAlert", "name": "HighCPUAlert", "type": "Microsoft.Insights/metricAlerts", "location": "global", "properties": { "description": "Alert when CPU usage is over 80%", "enabled": true } }
--condition - Defines the rule that triggers the alert
--action-group - Specifies who or what gets notified
This command shows the last 5 important actions or changes made in your resource group to help you understand what happened.
Terminal
az monitor activity-log list --resource-group myResourceGroup --max-events 5
Expected OutputExpected
[ { "eventName": {"value": "Start Virtual Machine", "localizedValue": "Start Virtual Machine"}, "eventTimestamp": "2024-06-01T11:55:00Z", "resourceGroupName": "myResourceGroup", "status": {"value": "Succeeded", "localizedValue": "Succeeded"} }, { "eventName": {"value": "Create Virtual Machine", "localizedValue": "Create Virtual Machine"}, "eventTimestamp": "2024-05-30T09:00:00Z", "resourceGroupName": "myResourceGroup", "status": {"value": "Succeeded", "localizedValue": "Succeeded"} } ]
--max-events - Limits how many recent events to show
Key Concept

If you remember nothing else from this pattern, remember: monitoring helps you see problems early so you can fix them before users notice.

Common Mistakes
Not setting up alerts after checking metrics
You might miss critical problems because you are not notified automatically
Always create alerts for important metrics to get notified immediately
Checking metrics for the wrong resource or with wrong names
You get no data or wrong data, so you can't trust your monitoring
Double-check resource IDs and metric names before running commands
Ignoring activity logs
You miss understanding what changes caused issues
Regularly review activity logs to track changes and troubleshoot
Summary
Use 'az monitor metrics list' to check performance data like CPU usage.
Create alerts with 'az monitor metrics alert create' to get notified about problems.
Review activity logs with 'az monitor activity-log list' to see recent changes.