Azure Monitor
Metrics · diagnostic settings · Log Analytics workspaces · Azure Monitor Agent · KQL
By the tools4free.dev team · Last reviewed November 13, 2026
Practice questions for this topic →
Metrics and logs
| Metrics | Logs | |
|---|---|---|
| What it is | Numeric time series | Records stored in tables, collected and queried with a query language (KQL) |
| Platform data | Collected automatically from Azure resources, no configuration. Frequency is one minute unless the metric says otherwise | The activity log is collected automatically. Resource logs are not collected until you create a diagnostic setting |
| Retention | 93 days for platform and custom metrics. One chart in Metrics explorer can query at most 30 days; select 30 days, then pan to see the rest of the 93 | Set per table. Each table can keep data up to 12 years. Search jobs bring long-term data back to interactive |
| Cost | No ingestion or storage charge for platform metrics | No direct cost to create a workspace. You pay for ingestion and retention per table plan |
Moving or renaming an Azure resource can lose its metric history. To trend metrics for longer than 93 days, send them to a Log Analytics workspace with a diagnostic setting.
- Multi-dimensional metrics carry name/value dimensions (for example Drive=C:), so you can filter or split a chart. Dimension names and values are case-insensitive.
- Activity log vs resource logs: the activity log (subscription control-plane events) is automatic. Resource logs (from inside the resource) need a diagnostic setting.
Host data vs guest data
- Host metrics for a VM (CPU, network, disk I/O) are collected automatically at no cost. Guest metrics need enhanced monitoring, which installs Azure Monitor Agent.
- Guest OS data (Windows events, Syslog, performance counters, IIS logs, text logs) needs Azure Monitor Agent plus a data collection rule (DCR).
- Diagnostic setting vs DCR: a diagnostic setting routes Azure platform data from a resource. A DCR defines what Azure Monitor Agent collects from a VM.
- At scale: install Azure Monitor Agent, create one or more DCRs, then associate the DCRs with the VM. The agent installs once and can use any number of DCRs.
- The Log Analytics agent was retired in August 2024. Use Azure Monitor Agent.
Diagnostic settings
| Item | Rule |
|---|---|
| Sends | Resource logs, platform metrics or the activity log |
| Destinations | Log Analytics workspace, Storage account, Event Hubs, partner solutions |
| Settings per resource | 5 |
| Destinations of the same type per setting | 1. Create another setting for another workspace, storage account or event hub |
| Destination must exist | Before you create the setting. Log Analytics tables are created automatically when the first data arrives |
| Region | For regional resources, the Storage account and Event Hubs destination must be in the same region as the monitored resource |
| Storage account type | Standard accounts only. Premium accounts and accounts with DNS zone endpoints are not supported |
| Storage or event hub with a firewall or VNet | Turn on Allow trusted Microsoft services to bypass this firewall |
| Event Hubs permissions | Manage, Send and Listen on the namespace authorization rule. Updating the setting needs ListKey |
| Other subscription or tenant | Another subscription works if you have RBAC access to both. For another Microsoft Entra tenant, use Azure Lighthouse |
| Timing | Data should start flowing within 90 minutes. If nothing arrives after 24 hours, there is a problem |
- Portal: resource › Monitoring › Diagnostic settings › Add diagnostic setting › name it › pick a category group (
allLogsoraudit) or individual categories › tick AllMetrics if you want metrics › choose destinations › Save. - Activity log export: portal uses Export activity log. CLI uses the subscription-scope command.
New-AzDiagnosticSettingcannot be used for the activity log; use an ARM template. - Delete diagnostic settings when you delete, rename or move a resource. Otherwise a re-created resource can inherit the old setting.
Log Analytics workspace and queries
- A workspace stores log data in tables. Each table has its own plan and retention.
- To query a workspace you need
Microsoft.OperationalInsights/workspaces/query/*/read, which the Log Analytics Reader built-in role provides. - KQL table and column names are case sensitive. Keywords are usually lowercase.
- Log Analytics has KQL mode and Simple mode (point-and-click filters). The Logs time picker defaults to the last 24 hours.
KQL examples
| Query | What it returns |
|---|---|
SecurityEvent | take 10 | 10 arbitrary rows, in no particular order. Good for seeing the table shape |
SecurityEvent | top 10 by TimeGenerated | The 10 latest rows. top sorts on the server; descending is the default |
SecurityEvent | where Level == 8 and EventID == 4672 | Only rows that match both conditions. == is case-sensitive; =~ is case-insensitive |
SecurityEvent | where TimeGenerated > ago(30m) | where toint(Level) >= 10 | Rows from the last 30 minutes with Level of 10 or more. Level is a string, so cast it with toint. ago units include m, d and s |
SecurityEvent | top 10 by TimeGenerated | project TimeGenerated, Computer, Activity | Only the three listed columns. project selects or renames columns |
SecurityEvent | top 10 by TimeGenerated | extend EventCode=substring(Activity, 0, 4) | All original columns plus one new computed column. extend keeps all columns |
Perf | where TimeGenerated > ago(1h) | summarize count() by ObjectName | One row per ObjectName with the number of Perf records in the last hour |
Perf | where TimeGenerated > ago(1h) | summarize avg(CounterValue) by Computer, CounterName | The average per computer and counter. Group by both so the values are meaningful |
Perf | where TimeGenerated > ago(7d) | where Computer == "DC01.na.contosohotels.com" | where CounterName == "Available MBytes" | summarize avg(CounterValue) by bin(TimeGenerated, 1h) | Hourly average free memory for a week. bin buckets continuous values. Switch to Chart view to see a time chart |
search in (SecurityEvent) "Cryptographic" | take 10 | 10 rows where any column contains the phrase. Slower than a table-based where filter |
Perf | where TimeGenerated > ago(7d) | where CounterName == "Available MBytes" | summarize avg(CounterValue) by bin(TimeGenerated, 1h) | render timechart | The hourly averages drawn as a time chart. render must be the last operator |
- take vs top:
takereturns arbitrary rows;topreturns ordered rows. - project vs extend:
projectreturns only the chosen columns;extendkeeps all columns and adds more. - render: the operator only tells the client to visualize the result. It must be the last operator and works only on a query that produces a single tabular data stream. Syntax:
T | render visualization. Kinds includetimechart,barchartandpiechart.
CLI and PowerShell
| Task | Azure CLI | PowerShell |
|---|---|---|
| Create a resource diagnostic setting | az monitor diagnostic-settings create --name N --resource <id> --logs '[{"category":"AuditEvent","enabled":true}]' --metrics '[{"category":"AllMetrics","enabled":true}]' --workspace <id> | New-AzDiagnosticSetting -Name N -ResourceId <id> -WorkspaceId <id> -Log $log -Metric $metric |
| Export the activity log | az monitor diagnostic-settings subscription create (or update) | Not supported with New-AzDiagnosticSetting; use an ARM template |
| Use resource-specific tables | Add --export-to-resource-specific true | Not covered on the page |
| Install Azure Monitor Agent on a Windows VM | az vm extension set --name AzureMonitorWindowsAgent --publisher Microsoft.Azure.Monitor --vm-name VM --resource-group RG | Not covered on the page |
| Associate a DCR with a VM | az monitor data-collection rule association create --name A --rule-id <dcr> --resource <vm id> | New-AzDataCollectionRuleAssociation -AssociationName A -ResourceUri <vm id> -DataCollectionRuleId <dcr> |
| Read metrics | az monitor metrics command group | Az.Monitor module cmdlets |
Exam Tips
Tick each tip once you can answer it without looking.
“Archive a resource's logs in a storage account” → Diagnostic setting to a Standard storage account. Trap: Premium storage accounts aren't supported as a destination.
“Stream resource logs to a third-party SIEM” → Diagnostic setting to Event Hubs. Trap: A storage account is a static store, not a stream.
“Diagnostic setting to a storage account in another region fails” → For a regional resource the storage account must be in the same region. Trap: Any region works.
“Diagnostic setting can't write to a storage account that has a firewall” → Turn on Allow trusted Microsoft services to bypass this firewall.
“Send one resource's logs to two Log Analytics workspaces” → Two diagnostic settings. Trap: A setting takes one destination of each type.
“A sixth diagnostic setting on one resource” → Not possible: the limit is 5 per resource. Trap: The limit is per resource, not per subscription.
“Export the subscription activity log with the CLI” → az monitor diagnostic-settings subscription create. Trap: New-AzDiagnosticSetting can't export the activity log; use an ARM template.
“No data 24 hours after creating a diagnostic setting” → Something is wrong: data should start within 90 minutes.
“Resource logs aren't showing up in a workspace” → Create a diagnostic setting. Trap: Only the activity log and platform metrics are collected automatically.
“Metrics chart is blank at a 90-day range” → A chart spans at most 30 days: pick 30 days and pan within the 93-day retention. Trap: Metrics are kept 93 days, not 30.
“Metric history disappeared after renaming a resource” → Expected: moving or renaming a resource can lose metric history. Trap: It isn't a retention setting.
“Collect Windows event logs and Syslog from VMs” → Azure Monitor Agent plus a data collection rule, sent to a Log Analytics workspace. Trap: Diagnostic settings route platform data from a resource; the Log Analytics agent was retired in August 2024.
“Guest memory metrics are missing for a VM” → Enable guest monitoring (Azure Monitor Agent). Trap: Host metrics give overall performance and load (CPU, network traffic, disk I/O), not guest data.
“Recreated a VM with the same name and logs flow again” → The old diagnostic setting was never deleted: delete settings when you delete, rename or move a resource. Trap: Settings don't disappear with the resource.
“A user must read workspace data but not change it” → Log Analytics Reader (provides Microsoft.OperationalInsights/workspaces/query/*/read).
“Show only the Computer and Activity columns” → project. Trap: extend keeps all columns and adds more.
“Get the 10 latest rows” → top 10 by TimeGenerated. Trap: take 10 returns arbitrary rows in no particular order.
“Show hourly averages as a time chart” → | summarize ... by bin(TimeGenerated, 1h) | render timechart. Trap: render must be the last operator, so it can't come before summarize.
Sources
- Metrics in Azure Monitor
- Diagnostic settings in Azure Monitor
- Get started with log queries
- Log Analytics workspace overview
- Azure Monitor data sources
- Monitor virtual machines in Azure
- Enable VM monitoring in Azure Monitor
- render operator (Kusto Query Language)
Checked against Microsoft Learn on November 13, 2026.