Azure Resource Graph-exempelfrågor för Azure Resource Health

Den här sidan är en samling Azure Resource Graph-exempelfrågor för Azure Resource Health.

Anmärkning

Efter varje fråga bör du se de uppdaterade resultaten inom 5 minuter i allmänhet.

Översikt

Den här sidan hjälper dig att övervaka och förstå hälsotillståndet för dina Azure-tjänster och -resurser med kusto query language (KQL) via Azure Resource Graph.

Den innehåller exempelfrågor specifikt för Azure Resource Health.

Resource Health-exempelfrågor

Antal virtuella datorer efter tillgänglighetstillstånd och prenumerations-ID

Den här frågan visar hur många virtuella datorer (Microsoft.Compute/virtualMachines) som är i varje tillgänglighetstillstånd, grupperade efter var och en av dina prenumerationer.

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)"

Listor över virtuella datorer och associerade tillgänglighetstillstånd efter resurs-ID

Den här frågan visar den senaste listan över virtuella datorer (VM) (Microsoft.Compute/virtualMachines) grupperade efter deras tillgänglighetstillstånd. Frågan innehåller även varje virtuell maskins resurs-ID (properties.targetResourceId) för att underlätta felsökning och förebyggande av problem.

Tillgänglighetstillstånd kan vara ett av fyra värden: Tillgängligt, Otillgängligt, Degraderat eller Okänt.
Mer information om vad varje tillstånd innebär finns i Översikt över Azure Resource Health.

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)"

Listor över virtuella datorer efter tillgänglighet och energitillstånd med resurs-ID:t och resursgrupper

Den här frågan hämtar en lista över virtuella datorer (Microsoft.Compute/virtualMachines) och sammanfattar deras hälsa genom att aggregera både deras energitillstånd och tillgänglighetstillstånd.
Frågan innehåller också information om resursgruppen och resurs-ID:t som är associerade med varje post för detaljerad insyn i dina resurser.

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'"

Listor över virtuella datorer som inte är tillgängliga efter resurs-ID:er

Den här frågan visar de senaste virtuella datorerna (VM) (Microsoft.Compute/virtualMachines) som inte är i ett tillgängligt tillstånd och grupperade efter deras tillgänglighetsstatus.
Den innehåller även resurs-ID :t (från properties.targetResourceId) för varje virtuell dator för felsökning.

Om alla dina virtuella datorer är i tillståndet Tillgänglig returnerar frågan inga resultat.

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)"

Nästa steg