Skip to content

Commit 01f5da9

Browse files
authored
Merge pull request #262678 from AbbyMSFT/log-alerts-adx
Changes to query examples for log alert rules
2 parents 8cf5707 + 7c7a266 commit 01f5da9

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

articles/azure-monitor/alerts/alerts-log-alert-query-samples.md

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,24 @@ ms.reviewer: nolavime
1010

1111
# Sample log alert queries that include ADX and ARG
1212

13-
A log alert rule monitors a resource by using a Log Analytics query to evaluate resource logs at a set frequency. You can include data from Azure Data Explorer and Azure Resource Graph in your log alert rule queries.
13+
A log alert rule monitors a resource by using a Log Analytics query to evaluate logs at a set frequency. You can include data from Azure Data Explorer and Azure Resource Graph in your log alert rule queries.
1414

1515
This article provides examples of log alert rule queries that use Azure Data Explorer and Azure Resource Graph. For more information about creating a log alert rule, see [Create a log alert rule](./alerts-create-log-alert-rule.md).
1616

17-
## Query that checks virtual machine health
17+
## Queries that check virtual machine health
1818

19-
This query finds virtual machines that are marked as critical and that had a heartbeat more than 24 hours ago, but that haven't had a heartbeat in the last 2 minutes.
19+
This query finds virtual machines marked as critical that haven't had a heartbeat in the last 2 minutes.
20+
21+
```kusto
22+
arg("").Resources
23+
| where type == "microsoft.compute/virtualmachines"
24+
| summarize LastCall = max(case(isnull(TimeGenerated), make_datetime(1970, 1, 1), TimeGenerated)) by name, id
25+
| extend SystemDown = case(LastCall < ago(2m), 1, 0)
26+
| where SystemDown == 1
27+
```
28+
29+
30+
This query finds virtual machines marked as critical that had a heartbeat more than 24 hours ago, but that haven't had a heartbeat in the last 2 minutes.
2031

2132
```kusto
2233
{
@@ -38,15 +49,15 @@ This query finds virtual machines that are marked as critical and that had a hea
3849
## Query that filters virtual machines that need to be monitored
3950

4051
```kusto
41-
{
52+
{
4253
let RuleGroupTags = dynamic(['Linux']);
43-
Perf | where ObjectName == 'Processor' and CounterName == '% Idle Time' and (InstanceName == '_Total' or InstanceName == 'total')
54+
Perf | where ObjectName == 'Processor' and CounterName == '% Idle Time' and (InstanceName in ('_Total,'total'))
4455
| extend CpuUtilisation = (100 - CounterValue)   
4556
| join kind=inner hint.remote=left (arg("").Resources
46-
| where type =~ 'Microsoft.Compute/virtualMachines'
57+
| where type =~ 'Microsoft.Compute/virtualMachines'
4758
| project _ResourceId=tolower(id), tags) on _ResourceId
4859
| project-away _ResourceId1
49-
| where (isnull(tags.monitored) or tolower(tostring(tags.monitored)) != 'false') and (tostring(tags.monitorRuleGroup) in (RuleGroupTags) or isnull(tags.monitorRuleGroup) or tostring(tags.monitorRuleGroup) == '')
60+
| where (tostring(tags.monitorRuleGroup) in (RuleGroupTags))
5061
}
5162
```
5263

@@ -68,10 +79,10 @@ This query finds virtual machines that are marked as critical and that had a hea
6879
```kusto
6980
{
7081
arg("").resourcechanges
71-
| extend changeTime = todatetime(properties.changeAttributes.timestamp), targetResourceId = tostring(properties.targetResourceId),
82+
| extend changeTime = todatetime(properties.changeAttributes.timestamp),
7283
changeType = tostring(properties.changeType),targetResourceType = tostring(properties.targetResourceType),
7384
changedBy = tostring(properties.changeAttributes.changedBy)
74-
| where changeType == "Create"
85+
| where changeType == "Create" and changeTime <ago(1h)
7586
| project changeTime,targetResourceId,changedBy
7687
}
7788
```

0 commit comments

Comments
 (0)