Skip to content

Commit c69c433

Browse files
committed
changes to query examples for log alert rules
1 parent 7bf33ed commit c69c433

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

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

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,20 @@ A log alert rule monitors a resource by using a Log Analytics query to evaluate
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)