本页是 Azure Resource Health 的 Azure Resource Graph 示例查询的集合。
注释
每次查询后,通常会在 5 分钟内看到更新的结果。
概述
本页可帮助你通过 Azure Resource Graph 使用 Kusto 查询语言(KQL)监视和了解 Azure 服务和资源的运行状况。
它包括专门针对 Azure 资源运行状况的示例查询。
资源健康示例查询
按可用性和订阅 ID 的状态计算虚拟机计数
此查询显示每个可用性状态下有多少个虚拟机(Microsoft.Compute/virtualMachines
按每个订阅分组)。
HealthResources
| where type =~ 'microsoft.resourcehealth/availabilitystatuses'
| summarize count() by subscriptionId, AvailabilityState = tostring(properties.availabilityState)
az graph query -q "HealthResources | where type =~ 'microsoft.resourcehealth/availabilitystatuses' | summarize count() by subscriptionId, AvailabilityState = tostring(properties.availabilityState)"
按资源 ID 列出的虚拟机和关联的可用性状态列表
此查询列出按其可用性状态分组的虚拟机(VM)的最新Microsoft.Compute/virtualMachines
列表。 该查询还包括每个 VM 的资源 ID(properties.targetResourceId
),以帮助进行调试和故障排除。
可用性状态可以是四个值之一: 可用、 不可用、 降级或 未知。
有关每个状态的含义的详细信息,请参阅 Azure 资源运行状况概述。
HealthResources
| where type =~ 'microsoft.resourcehealth/availabilitystatuses'
| summarize by ResourceId = tolower(tostring(properties.targetResourceId)), AvailabilityState = tostring(properties.availabilityState)
az graph query -q "HealthResources | where type =~ 'microsoft.resourcehealth/availabilitystatuses' | summarize by ResourceId = tolower(tostring(properties.targetResourceId)), AvailabilityState = tostring(properties.availabilityState)"
通过资源 ID 和资源组按可用性和电源状态列出的虚拟机列表
此查询通过聚合其电源状态和可用性状态来检索虚拟机列表(Microsoft.Compute/virtualMachines
)并汇总其运行状况。
该查询还提供与每个条目关联的资源组和资源 ID 的详细信息,以详细查看资源。
Resources
| where type =~ 'microsoft.compute/virtualmachines'
| project resourceGroup, Id = tolower(id), PowerState = tostring( properties.extended.instanceView.powerState.code)
| join kind=leftouter (
HealthResources
| where type =~ 'microsoft.resourcehealth/availabilitystatuses'
| where tostring(properties.targetResourceType) =~ 'microsoft.compute/virtualmachines'
| project targetResourceId = tolower(tostring(properties.targetResourceId)), AvailabilityState = tostring(properties.availabilityState))
on $left.Id == $right.targetResourceId
| project-away targetResourceId
| where PowerState != 'PowerState/deallocated'
az graph query -q "Resources | where type =~ 'microsoft.compute/virtualmachines' | project resourceGroup, Id = tolower(id), PowerState = tostring( properties.extended.instanceView.powerState.code) | join kind=leftouter ( HealthResources | where type =~ 'microsoft.resourcehealth/availabilitystatuses' | where tostring(properties.targetResourceType) =~ 'microsoft.compute/virtualmachines' | project targetResourceId = tolower(tostring(properties.targetResourceId)), AvailabilityState = tostring(properties.availabilityState)) on \$left.Id == \$right.targetResourceId | project-away targetResourceId | where PowerState != 'PowerState/deallocated'"
不能通过资源 ID 查询的虚拟机列表
此查询列出了未处于Microsoft.Compute/virtualMachines
状态且按其可用性状态分组的最新虚拟机(VM)。
它还包括每个 VM 的资源 ID(来自 properties.targetResourceId),以帮助进行故障排除。
如果所有虚拟机都处于 “可用”状态,查询将不返回任何结果。
HealthResources
| where type =~ 'microsoft.resourcehealth/availabilitystatuses'
| where tostring(properties.availabilityState) != 'Available'
| summarize by ResourceId = tolower(tostring(properties.targetResourceId)), AvailabilityState = tostring(properties.availabilityState)
az graph query -q "HealthResources | where type =~ 'microsoft.resourcehealth/availabilitystatuses' | where tostring(properties.availabilityState) != 'Available' | summarize by ResourceId = tolower(tostring(properties.targetResourceId)), AvailabilityState = tostring(properties.availabilityState)"