40 minutes
- Resource group: Create new rg-az104-lab17
- Name: law-az104lab17
- Region: East US
- Create.
Diagnostic data is not retroactive. Enable diagnostic settings BEFORE you want to start collecting logs. Historical data cannot be recovered.
Send metrics/logs to the Log Analytics workspace:
- Storage accounts > Create. Resource group: rg-az104-lab17,
Name: stoaz104lab17. Create.
+ Add diagnostic setting:
- Diagnostic setting name: diag-storage17
- Logs: check StorageRead, StorageWrite, StorageDelete
- Metrics: check Transaction
- Send to Log Analytics workspace: Enabled
- Log Analytics workspace: law-az104lab17
- Save.
Diagnostic data now flows from the storage account to Log Analytics.
- Virtual machines > Create > vm-monitor01, Ubuntu 22.04 LTS,
Standard_B1s, rg-az104-lab17. Create.
Configure).
- Log Analytics workspace: law-az104lab17
- Configure — the Portal automatically installs the Azure Monitor Agent
(AMA) and sets up data collection rules (DCRs) for performance metrics.
After a few minutes, performance data (CPU, memory, disk) flows into Log Analytics.
``kql
AzureActivity
| where ResourceGroup == "rg-az104-lab17"
| project TimeGenerated, OperationNameValue, Caller, ActivityStatusValue
| order by TimeGenerated desc
| take 20
`
This shows recent activity log entries for the resource group.
`kql
Perf
| where ObjectName == "Processor" and CounterName == "% Processor Time"
| summarize avg(CounterValue) by bin(TimeGenerated, 5m), Computer
| order by TimeGenerated desc
`
This aggregates CPU usage by 5-minute bins.
- Resource group: rg-az104-lab17
- Action group name: ag-az104lab17
- Display name: AG Lab 17
- Notification type: Email/SMS message/Push notification/Voice
- Name: admin-email
- Email address: your email
- Add.
Set alert thresholds conservatively to avoid alert fatigue. A threshold too low will trigger false alarms; too high will miss real issues. Start with typical peak usage + 20%.
- Resource: select vm-monitor01
- Signal name: Percentage CPU
- Operator: Greater than
- Threshold: 80
- Aggregation period: 5 minutes
- Frequency of evaluation: 1 minute
- Action group: select ag-az104lab17
- Alert rule name: alert-high-cpu
- Severity: 2
Now, if the VM's CPU exceeds 80% for 5 minutes, an alert fires and sends an
email/notification via the action group.
- Resource: select law-az104lab17 (Log Analytics workspace)
- Signal name: Custom log search
- Search query:
`kql
AzureActivity
| where ActivityStatusValue == "Failed"
| summarize Count = count() by bin(TimeGenerated, 15m)
`
- Threshold: Count > 5
- Evaluation frequency: 5 minutes
- Lookback period: 15 minutes
- Action group: ag-az104lab17
- Alert rule name: alert-failed-ops
- Severity: 3
This log alert fires if more than 5 failed operations occur in a 15-minute window.
and sending performance metrics returns results created with email notification