Skip to content

Commit 1f236b2

Browse files
authored
Merge pull request #250404 from osalzberg/docs-editor/azure-monitor-data-explorer-pr-1693982776
Added examples to ARG query
2 parents b697683 + 2b633b9 commit 1f236b2

File tree

1 file changed

+53
-5
lines changed

1 file changed

+53
-5
lines changed

articles/azure-monitor/logs/azure-monitor-data-explorer-proxy.md

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ ms.author: guywild
66
ms.topic: conceptual
77
ms.date: 08/22/2023
88
ms.reviewer: osalzberg
9-
109
---
10+
1111
# Query data in Azure Data Explorer and Azure Resource Graph from Azure Monitor
1212
Azure Monitor lets you query data in [Azure Data Explorer](/azure/data-explorer/data-explorer-overview) and [Azure Resource Graph](../../governance/resource-graph/overview.md) from your Log Analytics workspace and Application Insights resources. This article explains how to query data in Azure Resource Graph and Azure Data Explorer from Azure Monitor.
1313

@@ -51,7 +51,8 @@ union customEvents, adx('https://help.kusto.windows.net/Samples').StormEvents
5151
```kusto
5252
let CL1 = adx('https://help.kusto.windows.net/Samples').StormEvents;
5353
union customEvents, CL1 | take 10
54-
```
54+
55+
```sql
5556
5657
> [!TIP]
5758
> Shorthand format is allowed: *ClusterName*/*InitialCatalog*. For example, `adx('help/Samples')` is translated to `adx('help.kusto.windows.net/Samples')`.
@@ -60,7 +61,7 @@ When you use the [`join` operator](/azure/data-explorer/kusto/query/joinoperator
6061
6162
For example:
6263
63-
```kusto
64+
kusto
6465
AzureDiagnostics
6566
| join hint.remote=left adx("cluster=ClusterURI").AzureDiagnostics on (ColumnName)
6667
```
@@ -90,6 +91,49 @@ For example:
9091
arg("").<Azure-Resource-Graph-table-name>
9192
```
9293

94+
Here are some sample Azure Log Analytics queries that use the new Azure Resource Graph cross-service query capabilities:
95+
96+
- Filter a Log Analytics query based on the results of an Azure Resource Graph query:
97+
98+
```kusto
99+
arg("").Resources
100+
| where type == "microsoft.compute/virtualmachines" and properties.hardwareProfile.vmSize startswith "Standard_D"
101+
| join (
102+
Heartbeat
103+
| where TimeGenerated > ago(1d)
104+
| distinct Computer
105+
)
106+
on $left.name == $right.Computer
107+
```
108+
109+
- Create an alert rule that applies only to certain resources taken from an ARG query:
110+
- Exclude resources based on tags – for example, not to trigger alerts for VMs with a “Test” tag.
111+
112+
```kusto
113+
arg("").Resources
114+
| where tags.environment=~'Test'
115+
| project name
116+
117+
```
118+
119+
- Retrieve performance data related to CPU utilization and filter to resources with the “prod” tag.
120+
121+
```kusto
122+
InsightsMetrics
123+
| where Name == "UtilizationPercentage"
124+
| lookup (
125+
arg("").Resources
126+
| where type == 'microsoft.compute/virtualmachines'
127+
| project _ResourceId=tolower(id), tags
128+
)
129+
on _ResourceId
130+
| where tostring(tags.Env) == "Prod"
131+
```
132+
133+
More use cases:
134+
- Use a tag to determine whether VMs should be running 24x7 or should be shut down at night.
135+
- Show alerts on any server that contains a certain number of cores.
136+
93137
### Combine Azure Resource Graph tables with a Log Analytics workspace
94138

95139
Use the `union` command to combine cluster tables with a Log Analytics workspace.
@@ -103,14 +147,16 @@ union AzureActivity, arg("").Resources
103147
```kusto
104148
let CL1 = arg("").Resources ;
105149
union AzureActivity, CL1 | take 10
106-
```
150+
151+
```sql
107152
108153
When you use the [`join` operator](/azure/data-explorer/kusto/query/joinoperator) instead of union, you're required to use a [`hint`](/azure/data-explorer/kusto/query/joinoperator#join-hints) to combine the data in Azure Resource Graph with the Log Analytics workspace. Use `Hint.remote={Direction of the Log Analytics Workspace}`. For example:
109154
110-
```kusto
155+
kusto
111156
Perf | where ObjectName == "Memory" and (CounterName == "Available MBytes Memory")
112157
| extend _ResourceId = replace_string(replace_string(replace_string(_ResourceId, 'microsoft.compute', 'Microsoft.Compute'), 'virtualmachines','virtualMachines'),"resourcegroups","resourceGroups")
113158
| join hint.remote=left (arg("").Resources | where type =~ 'Microsoft.Compute/virtualMachines' | project _ResourceId=id, tags) on _ResourceId | project-away _ResourceId1 | where tostring(tags.env) == "prod"
159+
114160
```
115161

116162
## Create an alert based on a cross-service query
@@ -127,3 +173,5 @@ To create a new alert rule based on a cross-service query, follow the steps in [
127173
## Next steps
128174
* [Write queries](/azure/data-explorer/write-queries)
129175
* [Perform cross-resource log queries in Azure Monitor](../logs/cross-workspace-query.md)
176+
177+

0 commit comments

Comments
 (0)