|
| 1 | +--- |
| 2 | +title: Alerts from Azure Monitor for VMs |
| 3 | +description: Describes how to create alert rules from performance data collected by Azure Monitor for VMs. |
| 4 | +ms.subservice: |
| 5 | +ms.topic: conceptual |
| 6 | +author: bwren |
| 7 | +ms.author: bwren |
| 8 | +ms.date: 03/23/2019 |
| 9 | + |
| 10 | +--- |
| 11 | + |
| 12 | +# How to create alerts from Azure Monitor for VMs |
| 13 | +[Alerts in Azure Monitor](../platform/alerts-overview.md) proactively notify you of interesting data and patterns in your monitoring data. Azure Monitor for VMs does not include pre-configured alert rules, but you can create your own based on data that it collects. This article provides guidance on creating alert rules, including a set of sample queries. |
| 14 | + |
| 15 | + |
| 16 | +## Alert rule types |
| 17 | +Azure Monitor has [different types of alert rules](../platform/alerts-overview.md#what-you-can-alert-on) based on the data being used to create the alert. All data collected by Azure Monitor for VMs is stored in Azure Monitor Logs which supports [log alerts](../platform/alerts-log.md). You cannot currently use [metric alerts](../platform/alerts-log.md) with performance data collected from Azure Monitor for VMs because the data is not collected into Azure Monitor Metrics. To collect data for metric alerts, install the [diagnostics extension](../platform/diagnostics-extension-overview.md) for Windows VMs or the [Telegraf agent](../platform/collect-custom-metrics-linux-telegraf.md) for Linux VMs to collect performance data into Metrics. |
| 18 | + |
| 19 | +There are two types of log alerts in Azure Monitor: |
| 20 | + |
| 21 | +- [Number of results alerts](../platform/alerts-unified-log.md#number-of-results-alert-rules) create a single alert when a query returns at least a specified number of records. These are ideal for non-numeric data such and Windows and Syslog events collected by the [Log Analytics agent](../platform/log-analytics-agent.md) or for analyzing performance trends across multiple computers. |
| 22 | +- [Metric measurement alerts](../platform/alerts-unified-log.md#metric-measurement-alert-rules) create a separate alert for each record in a query that has a value that exceeds a threshold defined in the alert rule. These alert rules are ideal for performance data collected by Azure Monitor for VMs since they can create individual alerts for each computer. |
| 23 | + |
| 24 | + |
| 25 | +## Alert rule details |
| 26 | +Since the target resource for log alert rules is always a Log Analytics workspace, the log query must include any filter for particular virtual machines or virtual machine scale sets. For metric measurement alert rules, summarize the query results by computer in order to evaluate each separately. |
| 27 | + |
| 28 | +Start by creating a new alert rule following the procedure in [Create, view, and manage log alerts using Azure Monitor](../platform/alerts-log.md). For the **Resource**, select the Log Analytics workspace that Azure Monitor VMs uses in your subscription. |
| 29 | + |
| 30 | +For the **Condition** of the alert rule, provide one of the queries in the section below as the **Search query**. The query must return a numeric property called *AggregatedValue*. It should summarize the data by computer so that you can create a separate alert for each virtual machine that exceeds the threshold. |
| 31 | + |
| 32 | +In the **Alert logic**, select **Metric measurement** and then provide a **Threshold value**. In **Trigger Alert Based On**, specify how many times the threshold must be exceeded before an alert is created. For example, you probably don't care if the processor exceeds a threshold once and then returns to normal, but you do care if it continues to exceed the threshold over multiple measurements. |
| 33 | + |
| 34 | +The **Evaluated based on** section defines how often the query is run and the time window for the query. In the example shown below, the query will run every 15 minutes and evalute performance collected over the previous 15 minutes. |
| 35 | + |
| 36 | + |
| 37 | + |
| 38 | + |
| 39 | +## Sample alert queries |
| 40 | +The following queries can be used with a metric measurement alert rule using performance data collected by Azure Monitor for VMs. Each summarizes data by computer so that an alert is created for each computer with a value that exceeds the threshold. |
| 41 | + |
| 42 | +### CPU utilization |
| 43 | + |
| 44 | +```kusto |
| 45 | +InsightsMetrics |
| 46 | +| where Origin == "vm.azm.ms" |
| 47 | +| where Namespace == "Processor" and Name == "UtilizationPercentage" |
| 48 | +| summarize AggregatedValue = avg(Val) by bin(TimeGenerated, 15m), Computer, _ResourceId |
| 49 | +``` |
| 50 | + |
| 51 | +### Available Memory in MB |
| 52 | + |
| 53 | +```kusto |
| 54 | +InsightsMetrics |
| 55 | +| where Origin == "vm.azm.ms" |
| 56 | +| where Namespace == "Memory" and Name == "AvailableMB" |
| 57 | +| summarize AggregatedValue = avg(Val) by bin(TimeGenerated, 15m), Computer, _ResourceId |
| 58 | +``` |
| 59 | + |
| 60 | +### Available Memory in percentage |
| 61 | + |
| 62 | +```kusto |
| 63 | +InsightsMetrics |
| 64 | +| where Origin == "vm.azm.ms" |
| 65 | +| where Namespace == "Memory" and Name == "AvailableMB" |
| 66 | +| extend TotalMemory = toreal(todynamic(Tags)["vm.azm.ms/memorySizeMB"]) |
| 67 | +| extend AvailableMemoryPercentage = (toreal(Val) / TotalMemory) * 100.0 |
| 68 | +| summarize AggregatedValue = avg(AvailableMemoryPercentage) by bin(TimeGenerated, 15m), Computer, _ResourceId |
| 69 | +``` |
| 70 | + |
| 71 | +### Logical disk used - all disks on each computer |
| 72 | + |
| 73 | +```kusto |
| 74 | +InsightsMetrics |
| 75 | +| where Origin == "vm.azm.ms" |
| 76 | +| where Namespace == "LogicalDisk" and Name == "FreeSpacePercentage" |
| 77 | +| summarize AggregatedValue = avg(Val) by bin(TimeGenerated, 15m), Computer, _ResourceId |
| 78 | +``` |
| 79 | + |
| 80 | +### Logical disk used - individual disks |
| 81 | + |
| 82 | +```kusto |
| 83 | +InsightsMetrics |
| 84 | +| where Origin == "vm.azm.ms" |
| 85 | +| where Namespace == "LogicalDisk" and Name == "FreeSpacePercentage" |
| 86 | +| extend Disk=tostring(todynamic(Tags)["vm.azm.ms/mountId"]) |
| 87 | +| summarize AggregatedValue = avg(Val) by bin(TimeGenerated, 15m), Computer, _ResourceId, Disk |
| 88 | +``` |
| 89 | + |
| 90 | +### Logical disk IOPS |
| 91 | + |
| 92 | +```kusto |
| 93 | +InsightsMetrics |
| 94 | +| where Origin == "vm.azm.ms" |
| 95 | +| where Namespace == "LogicalDisk" and Name == "TransfersPerSecond" |
| 96 | +| extend Disk=tostring(todynamic(Tags)["vm.azm.ms/mountId"]) |
| 97 | +| summarize AggregatedValue = avg(Val) by bin(TimeGenerated, 15m) ), Computer, _ResourceId, Disk |
| 98 | +``` |
| 99 | + |
| 100 | +### Logical disk data rate |
| 101 | + |
| 102 | +```kusto |
| 103 | +InsightsMetrics |
| 104 | +| where Origin == "vm.azm.ms" |
| 105 | +| where Namespace == "LogicalDisk" and Name == "BytesPerSecond" |
| 106 | +| extend Disk=tostring(todynamic(Tags)["vm.azm.ms/mountId"]) |
| 107 | +| summarize AggregatedValue = avg(Val) by bin(TimeGenerated, 15m) , Computer, _ResourceId, Disk |
| 108 | +``` |
| 109 | + |
| 110 | +### Network interfaces bytes received - all interfaces |
| 111 | + |
| 112 | +```kusto |
| 113 | +InsightsMetrics |
| 114 | +| where Origin == "vm.azm.ms" |
| 115 | +| where Namespace == "Network" and Name == "ReadBytesPerSecond" |
| 116 | +| summarize AggregatedValue = avg(Val) by bin(TimeGenerated, 15m), Computer, _ResourceId |
| 117 | +``` |
| 118 | + |
| 119 | +### Network interfaces bytes received - individual interfaces |
| 120 | + |
| 121 | +```kusto |
| 122 | +InsightsMetrics |
| 123 | +| where Origin == "vm.azm.ms" |
| 124 | +| where Namespace == "Network" and Name == "ReadBytesPerSecond" |
| 125 | +| extend NetworkInterface=tostring(todynamic(Tags)["vm.azm.ms/networkDeviceId"]) |
| 126 | +| summarize AggregatedValue = avg(Val) by bin(TimeGenerated, 15m), Computer, _ResourceId, NetworkInterface |
| 127 | +``` |
| 128 | + |
| 129 | +### Network interfaces bytes sent - all interfaces |
| 130 | + |
| 131 | +```kusto |
| 132 | +InsightsMetrics |
| 133 | +| where Origin == "vm.azm.ms" |
| 134 | +| where Namespace == "Network" and Name == "WriteBytesPerSecond" |
| 135 | +| summarize AggregatedValue = avg(Val) by bin(TimeGenerated, 15m), Computer, _ResourceId |
| 136 | +``` |
| 137 | + |
| 138 | +### Network interfaces bytes sent - individual interfaces |
| 139 | + |
| 140 | +```kusto |
| 141 | +InsightsMetrics |
| 142 | +| where Origin == "vm.azm.ms" |
| 143 | +| where Namespace == "Network" and Name == "WriteBytesPerSecond" |
| 144 | +| extend NetworkInterface=tostring(todynamic(Tags)["vm.azm.ms/networkDeviceId"]) |
| 145 | +| summarize AggregatedValue = avg(Val) by bin(TimeGenerated, 15m), Computer, _ResourceId, NetworkInterface |
| 146 | +``` |
| 147 | + |
| 148 | +## Virtual machine scale set |
| 149 | + |
| 150 | +```kusto |
| 151 | +InsightsMetrics |
| 152 | +| where Origin == "vm.azm.ms" |
| 153 | +| where _ResourceId startswith "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/my-resource-group/providers/Microsoft.Compute/virtualMachineScaleSets/my-vm-scaleset" |
| 154 | +| where Namespace == "Processor" and Name == "UtilizationPercentage" |
| 155 | +| summarize AggregatedValue = avg(Val) by bin(TimeGenerated, 15m), _ResourceId |
| 156 | +``` |
| 157 | + |
| 158 | +## Specific virtual machine |
| 159 | + |
| 160 | +```kusto |
| 161 | +InsightsMetrics |
| 162 | +| where Origin == "vm.azm.ms" |
| 163 | +| where _ResourceId =~ "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/my-resource-group/providers/Microsoft.Compute/virtualMachines/my-vm" |
| 164 | +| where Namespace == "Processor" and Name == "UtilizationPercentage" |
| 165 | +| summarize AggregatedValue = avg(Val) by bin(TimeGenerated, 15m) |
| 166 | +``` |
| 167 | + |
| 168 | +## CPU utilization for all compute resources in a subscription |
| 169 | + |
| 170 | +```kusto |
| 171 | +InsightsMetrics |
| 172 | +| where Origin == "vm.azm.ms" |
| 173 | +| where _ResourceId startswith "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" and (_ResourceId contains "/providers/Microsoft.Compute/virtualMachines/" or _ResourceId contains "/providers/Microsoft.Compute/virtualMachineScaleSets/") |
| 174 | +| where Namespace == "Processor" and Name == "UtilizationPercentage" |
| 175 | +| summarize AggregatedValue = avg(Val) by bin(TimeGenerated, 15m), _ResourceId |
| 176 | +``` |
| 177 | + |
| 178 | +## CPU utilization for all compute resources in a resource group |
| 179 | + |
| 180 | +```kusto |
| 181 | +InsightsMetrics |
| 182 | +| where Origin == "vm.azm.ms" |
| 183 | +| where _ResourceId startswith "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/my-resource-group/providers/Microsoft.Compute/virtualMachines/" |
| 184 | +or _ResourceId startswith "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/my-resource-group/providers/Microsoft.Compute/virtualMachineScaleSets/" |
| 185 | +| where Namespace == "Processor" and Name == "UtilizationPercentage" |
| 186 | +| summarize AggregatedValue = avg(Val) by bin(TimeGenerated, 15m), _ResourceId |
| 187 | +
|
| 188 | +``` |
| 189 | + |
| 190 | + |
| 191 | + |
| 192 | +## Next steps |
| 193 | + |
| 194 | +- Learn more about [alerts in Azure Monitor](../platform/alerts-overview.md). |
| 195 | +- Learn more about [log queries using data from Azure Monitor for VMs](vminsights-log-search.md). |
0 commit comments