Kaido Jarvemets - Logo

Understanding Azure Arc for Servers with KQL Queries

Azure Resource Graph provides a powerful querying capability across your Azure environment, and Kusto Query Language (KQL) is the key to unlocking this potential. In this blog post, we’ll explore three essential KQL queries for managing Azure Arc machines. These queries help in listing servers, counting them based on specific criteria, and joining data across different Azure tables.

Query 1: Listing All Azure Arc Machines

The first query is straightforward. It lists all Azure Arc machines (microsoft.hybridcompute/machines) in your environment.

				
					resources
| where type == "microsoft.hybridcompute/machines"

				
			

This query filters the resources table to only include entries of type microsoft.hybridcompute/machines, effectively listing all Azure Arc machines.

Query 2: Counting Azure Arc Machines by Subscription and Resource Group

The second query takes it a step further by not only listing the Azure Arc machines but also counting them, grouping by subscriptionId and resourceGroup.

				
					resources
| where type == "microsoft.hybridcompute/machines"
| summarize machineCount = count() by subscriptionId, resourceGroup

				
			

This aggregation is particularly useful for understanding the distribution of your Azure Arc machines across different subscriptions and resource groups.

Query 3: Enriching Azure Arc Machine Data with Subscription Names

The third query combines information from the resources and resourcecontainers tables to enrich the Azure Arc machine data with subscription names.

				
					resources
| where type == "microsoft.hybridcompute/machines"
| project serverName = name, subscriptionId, resourceGroup
| join kind=inner (
    resourcecontainers
    | where type == "microsoft.resources/subscriptions"
    | project subscriptionName = name, subscriptionId
) on subscriptionId
| summarize machineCount = count() by subscriptionId, subscriptionName, resourceGroup

				
			

In this query, we join the Azure Arc machine data with subscription information, providing a more comprehensive view of the machines, including their associated subscription names.

Query 4: Counting Azure Arc Machines by Status

This query focuses on understanding the distribution of machines based on their operational status.

				
					resources
| where type == "microsoft.hybridcompute/machines"
| extend machineStatus = tostring(properties.status)
| summarize machineCount = count() by machineStatus

				
			

Conclusion

These KQL queries are fundamental tools for anyone managing Azure environments. They provide insights into your Azure Arc machines, helping with effective resource management and strategic planning. Whether you’re listing, counting, or enriching data, KQL is an indispensable resource in your Azure toolkit.

Leave a Reply

Contact me

If you’re interested in learning about Understanding Azure Arc for Servers with KQL Queries. I can help you understand how this solution can benefit your organization and provide a customized solution tailored to your specific needs.

Table of Contents