Azure Monitor: alerts and log queries
Understand alert behavior, find alert instances, and learn how diagnostic settings send data to Log Analytics.
Who this is for: Azure administrators who work with Azure Monitor and Log Analytics.
Azure Monitor alert rules monitor resource data and notify people or start workflows when conditions are met. Log Analytics workspaces store data that you can retrieve with log queries.
This guide covers alert behavior, alert instances, and diagnostic settings. It does not include full procedures for creating alert rules, configuring diagnostic settings, or running queries.
Before you start
- Licenses: Azure is a pay-as-you-go (PAYG) service. Check your subscription and usage costs.
- Roles and access: You need appropriate Azure role-based access control (RBAC) permissions for the resources and actions in this guide. Ask your Azure administrator to confirm your access; Microsoft 365 roles do not grant Azure access.
- Cross-subscription destinations: If the destination is in a different subscription from the monitored resource, you need appropriate Azure RBAC access to both subscriptions.
- Log data: Have an existing Log Analytics workspace ready. The workspace must exist before data is sent; tables are created when the first data arrives.
| Azure Monitor concept | What it does |
|---|---|
| Log Analytics workspace | Receives data that you can retrieve with log queries and workbooks. Tables are created when the first data is sent. |
| Alert rule | Combines the resources to monitor, the signal or data, and conditions. An alert is triggered when its conditions are met. |
| Action group | Can notify people or start automated workflows when an alert is triggered. |
| Diagnostic setting | Defines which resource data to collect and which destinations receive it. |
A useful alert
An alert rule monitors selected resources and checks whether a signal meets its conditions. If a rule monitors multiple resources, Azure evaluates each resource separately and fires alerts separately.
- Metric alerts evaluate resource metrics at regular intervals.
- Log search alerts use a Log Analytics query to evaluate resource logs at a set frequency.
- Simple log search alerts use a Log Analytics query to evaluate each row individually.
- Activity log alerts respond to matching activity log events. Resource Health and Service Health alerts are activity log alerts.
- Prometheus alerts use PromQL for Prometheus metrics stored in Azure Monitor managed services for Prometheus.
- In the Azure portal, select Monitor > Alerts, or open a resource and select Alerts in the Monitoring section. Check whether the expected alert instance appears. If it does not, check the rule's resource, signal or data, and conditions. For a log-based alert, check that the workspace has received the relevant data.
- If a rule monitors multiple resources, check each resource separately. If multiple rules have the same conditions, each rule can fire independently.
- Choose stateful or stateless behavior based on whether repeated notifications are appropriate. Stateful alerts do not fire again or trigger more actions until their conditions are resolved. Stateless alerts fire each time their conditions are met.
- Check type-specific behavior when reviewing a rule. All activity log alerts are stateless.
Action groups can send notifications or start workflows, such as automation runbooks, Azure Functions, ITSM incidents, Logic Apps, webhooks, or Event Hubs. Confirm the setup requirements for an option before you select or configure it.
Alert instances are retained for 30 days and then deleted. Fired instances are read-only; rule changes affect future alerts, not existing instances.
Queries worth knowing
Log search alerts use a Log Analytics query, and Log Analytics workspaces let you retrieve data with log queries. This guide does not include query syntax, sample KQL, or steps for running a query. Ask your Azure administrator for help with the query procedure.
Platform metrics and activity log entries are collected automatically. Resource logs are not collected by default. Use a diagnostic setting to collect resource logs.
- In the Azure portal, open the monitored resource's menu and select Diagnostic settings in the Monitoring section. Or open Azure Monitor, select Settings, then Diagnostic settings, and select the resource. Confirm that you opened the setting for the resource whose logs you need.
- On the resource's Diagnostic settings page, select Add diagnostic setting to start creating a setting. This does not confirm that logs are being collected. Follow the complete procedure to select data and a destination, save the setting, and verify it.
- The destination must exist before you create a diagnostic setting.
- A setting can include no more than one destination of each type. Create multiple settings to send data to multiple destinations of the same type.
- A resource can have up to five diagnostic settings.
- If a Storage account or Event Hub is protected by a virtual network, allow trusted Microsoft services to bypass the firewall.
- For Event Hubs streaming, the shared access policy must provide Manage, Send, and Listen permissions. To update a diagnostic setting to include streaming, you need ListKey permission on the Event Hubs authorization rule.
When it goes wrong
- A log-based alert or query has no relevant data: resource logs are not collected by default. Check that the resource's diagnostic setting sends the required data to a Log Analytics workspace.
- A diagnostic setting cannot reach its destination: confirm that the destination exists, that a regional Storage account or Event Hub is in the monitored resource's region, and that trusted Microsoft services can bypass the firewall when virtual networks are enabled.
- You need to send data to multiple destinations of the same type: create multiple diagnostic settings, up to the limit of five per resource.
- A setting with Event Hubs streaming cannot be updated: check the shared access policy permissions and confirm you have ListKey permission on the authorization rule.
- A destination is in another subscription and access is denied: you need appropriate Azure RBAC access to both subscriptions. Ask your Azure administrator to grant access or use an accessible destination.
- A diagnostic setting remains after a resource is renamed, deleted, or moved across resource groups or subscriptions: remove the setting when you delete or rename the resource or migrate it. Otherwise, a setting for a deleted resource could apply to a recreated resource and resume log collection.
- An alert instance is missing after an extended period: instances are deleted after 30 days. Fired instances are read-only, and rule changes apply only to future alerts.
Related help articles
References
- https://learn.microsoft.com/en-us/azure/azure-monitor/alerts/alerts-overview
- https://learn.microsoft.com/en-us/azure/azure-monitor/alerts/alerts-page
- https://learn.microsoft.com/en-us/azure/azure-monitor/data-collection/diagnostic-settings
Last updated on