Azure Sanal Makineler için Azure Kaynak Grafı örnek sorguları
Bu sayfa, Azure Sanal Makineler için Azure Kaynak Grafı örnek sorgularından oluşan bir koleksiyondur.
Örnek sorgular
yapılan işletim sistemi güncelleştirme yüklemesinin sayısı
Makineleriniz için son yedi gün içinde yapılan işletim sistemi güncelleştirme yükleme çalıştırmalarının durumunun listesini döndürür.
PatchAssessmentResources
| where type !has 'softwarepatches'
| extend machineName = tostring(split(id, '/', 8)), resourceType = tostring(split(type, '/', 0)), tostring(rgName = split(id, '/', 4))
| extend prop = parse_json(properties)
| extend lTime = todatetime(prop.lastModifiedDateTime), OS = tostring(prop.osType), installedPatchCount = tostring(prop.installedPatchCount), failedPatchCount = tostring(prop.failedPatchCount), pendingPatchCount = tostring(prop.pendingPatchCount), excludedPatchCount = tostring(prop.excludedPatchCount), notSelectedPatchCount = tostring(prop.notSelectedPatchCount)
| where lTime > ago(7d)
| project lTime, RunID=name,machineName, rgName, resourceType, OS, installedPatchCount, failedPatchCount, pendingPatchCount, excludedPatchCount, notSelectedPatchCount
az graph query -q "PatchAssessmentResources | where type !has 'softwarepatches' | extend machineName = tostring(split(id, '/', 8)), resourceType = tostring(split(type, '/', 0)), tostring(rgName = split(id, '/', 4)) | extend prop = parse_json(properties) | extend lTime = todatetime(prop.lastModifiedDateTime), OS = tostring(prop.osType), installedPatchCount = tostring(prop.installedPatchCount), failedPatchCount = tostring(prop.failedPatchCount), pendingPatchCount = tostring(prop.pendingPatchCount), excludedPatchCount = tostring(prop.excludedPatchCount), notSelectedPatchCount = tostring(prop.notSelectedPatchCount) | where lTime > ago(7d) | project lTime, RunID=name,machineName, rgName, resourceType, OS, installedPatchCount, failedPatchCount, pendingPatchCount, excludedPatchCount, notSelectedPatchCount"
Kullanılabilirlik durumuna ve Abonelik Kimliğine göre sanal makinelerin sayısı
Aboneliklerinizin her birinde kullanılabilirlik durumlarına göre toplanan sanal makinelerin sayısını (tür Microsoft.Compute/virtualMachines
) döndürür.
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)"
Sanal makinelerin güç durumuna göre sayısı
Güç durumlarına göre kategorilere ayrılmış sanal makinelerin (tür Microsoft.Compute/virtualMachines
) sayısını döndürür. Güç durumları hakkında daha fazla bilgi için bkz . Güç durumlarına genel bakış.
Resources
| where type == 'microsoft.compute/virtualmachines'
| summarize count() by PowerState = tostring(properties.extended.instanceView.powerState.code)
az graph query -q "Resources | where type == 'microsoft.compute/virtualmachines' | summarize count() by PowerState = tostring(properties.extended.instanceView.powerState.code)"
Sanal makineleri işletim sistemi türüne göre sayma
Bir önceki sorguyu oluşturmada, hâlâ Microsoft.Compute/virtualMachines
türündeki Azure kaynaklarına göre sınırlandırıyoruz, ancak geri gönderilen kayıtların sayısını sınırlandırmıyoruz. Bunu yerine, değerleri (bu örnekte properties.storageProfile.osDisk.osType
) özelliğe göre gruplandırma ve toplamayı tanımlamak için summarize
ve count()
kullandık. Bu dizenin tam nesnede nasıl göründüğüne ilişkin bir örnek için, bkz. kaynakları keşfetme - sanal makine bulma.
Resources
| where type =~ 'Microsoft.Compute/virtualMachines'
| summarize count() by tostring(properties.storageProfile.osDisk.osType)
az graph query -q "Resources | where type =~ 'Microsoft.Compute/virtualMachines' | summarize count() by tostring(properties.storageProfile.osDisk.osType)"
Genişletme ile sanal makineleri işletim sistemi türüne göre sayma
'sanal makineleri işletim sistemi türüne göre say' sorgusunu yazmanın farklı bir yolu bir özelliğedir extend
ve bu durumda işletim sistemi içinde kullanmak üzere geçici bir ad verir. os daha sonra ve tarafından summarize
count()
başvurulmuş örnekte olduğu gibi kullanılır.
Resources
| where type =~ 'Microsoft.Compute/virtualMachines'
| extend os = properties.storageProfile.osDisk.osType
| summarize count() by tostring(os)
az graph query -q "Resources | where type =~ 'Microsoft.Compute/virtualMachines' | extend os = properties.storageProfile.osDisk.osType | summarize count() by tostring(os)"
Son 30 günün tüm Yeni uyarılarını alma
Bu sorgu, son 30 güne ait tüm kullanıcının Yeni uyarılarının listesini sağlar.
iotsecurityresources
| where type == 'microsoft.iotsecurity/locations/devicegroups/alerts'
| where todatetime(properties.startTimeUtc) > ago(30d) and properties.status == 'New'
az graph query -q "iotsecurityresources | where type == 'microsoft.iotsecurity/locations/devicegroups/alerts' | where todatetime(properties.startTimeUtc) > ago(30d) and properties.status == 'New'"
Sanal makine ölçek kümesi kapasitesini ve boyutunu alma
Bu sorgu, sanal makine ölçek kümesi kaynaklarını arar ve sanal makine boyutu ve ölçek kümesinin kapasitesini içeren çeşitli ayrıntıları alır. Sorgu, sıralanabilmesi için ve kapasiteyi bir sayıya dönüştürmek amacıyla toint()
işlevini kullanır. Son olarak sütunlar, özel olarak adlandırılmış özellikler kullanılarak yeniden adlandırılır.
Resources
| where type=~ 'microsoft.compute/virtualmachinescalesets'
| where name contains 'contoso'
| project subscriptionId, name, location, resourceGroup, Capacity = toint(sku.capacity), Tier = sku.name
| order by Capacity desc
az graph query -q "Resources | where type=~ 'microsoft.compute/virtualmachinescalesets' | where name contains 'contoso' | project subscriptionId, name, location, resourceGroup, Capacity = toint(sku.capacity), Tier = sku.name | order by Capacity desc"
Sanal makinede yüklü tüm uzantıları listeleme
İlk olarak, bu sorgu kimliği büyük harfle (toupper()
) almak, işletim sistemi adını ve türünü almak ve sanal makine boyutunu almak için sanal makine kaynak türünü kullanırextend
. Kaynak kimliğini büyük harfle almak, başka bir özelliğe katılmaya hazırlanmak için iyi bir yoldur. Ardından sorgu join
, ile kullanarak kind
leftouter
uzantı kimliğinin büyük substring
harflerini eşleştirerek sanal makine uzantılarını alır. Kimliğin önceki /extensions/\<ExtensionName\>
bölümü sanal makine kimliğiyle aynı biçimde olduğundan, için bu özelliği join
kullanırız. summarize
daha sonra id, OSName, OSType ve VMSize'ın aynı olduğu her uzantının adını tek bir dizi özelliğinde birleştirmek için sanal makine uzantısının adında ile make_list
birlikte kullanılır. Son olarak, OSName değerini ile küçük harfe asc
dönüştürürizorder by
. Varsayılan olarak azalan order by
değerdir.
Resources
| where type == 'microsoft.compute/virtualmachines'
| extend
JoinID = toupper(id),
OSName = tostring(properties.osProfile.computerName),
OSType = tostring(properties.storageProfile.osDisk.osType),
VMSize = tostring(properties.hardwareProfile.vmSize)
| join kind=leftouter(
Resources
| where type == 'microsoft.compute/virtualmachines/extensions'
| extend
VMId = toupper(substring(id, 0, indexof(id, '/extensions'))),
ExtensionName = name
) on $left.JoinID == $right.VMId
| summarize Extensions = make_list(ExtensionName) by id, OSName, OSType, VMSize
| order by tolower(OSName) asc
az graph query -q "Resources | where type == 'microsoft.compute/virtualmachines' | extend JoinID = toupper(id), OSName = tostring(properties.osProfile.computerName), OSType = tostring(properties.storageProfile.osDisk.osType), VMSize = tostring(properties.hardwareProfile.vmSize) | join kind=leftouter( Resources | where type == 'microsoft.compute/virtualmachines/extensions' | extend VMId = toupper(substring(id, 0, indexof(id, '/extensions'))), ExtensionName = name ) on \$left.JoinID == \$right.VMId | summarize Extensions = make_list(ExtensionName) by id, OSName, OSType, VMSize | order by tolower(OSName) asc"
Güncelleştirme kategorisine göre gruplandırılmış tüm makineleriniz için kullanılabilir işletim sistemi güncelleştirmelerini listeleme
Makineleriniz için bekleyen işletim sisteminin listesini döndürür.
PatchAssessmentResources
| where type !has 'softwarepatches'
| extend prop = parse_json(properties)
| extend lastTime = properties.lastModifiedDateTime
| extend updateRollupCount = prop.availablePatchCountByClassification.updateRollup, featurePackCount = prop.availablePatchCountByClassification.featurePack, servicePackCount = prop.availablePatchCountByClassification.servicePack, definitionCount = prop.availablePatchCountByClassification.definition, securityCount = prop.availablePatchCountByClassification.security, criticalCount = prop.availablePatchCountByClassification.critical, updatesCount = prop.availablePatchCountByClassification.updates, toolsCount = prop.availablePatchCountByClassification.tools, otherCount = prop.availablePatchCountByClassification.other, OS = prop.osType
| project lastTime, id, OS, updateRollupCount, featurePackCount, servicePackCount, definitionCount, securityCount, criticalCount, updatesCount, toolsCount, otherCount
az graph query -q "PatchAssessmentResources | where type !has 'softwarepatches' | extend prop = parse_json(properties) | extend lastTime = properties.lastModifiedDateTime | extend updateRollupCount = prop.availablePatchCountByClassification.updateRollup, featurePackCount = prop.availablePatchCountByClassification.featurePack, servicePackCount = prop.availablePatchCountByClassification.servicePack, definitionCount = prop.availablePatchCountByClassification.definition, securityCount = prop.availablePatchCountByClassification.security, criticalCount = prop.availablePatchCountByClassification.critical, updatesCount = prop.availablePatchCountByClassification.updates, toolsCount = prop.availablePatchCountByClassification.tools, otherCount = prop.availablePatchCountByClassification.other, OS = prop.osType | project lastTime, id, OS, updateRollupCount, featurePackCount, servicePackCount, definitionCount, securityCount, criticalCount, updatesCount, toolsCount, otherCount"
Yapılan Linux işletim sistemi güncelleştirme yüklemesinin listesi
Son yedi gün içinde makineleriniz için yapılan Linux Server - İşletim sistemi güncelleştirme yükleme çalıştırmalarının durumunun listesini döndürür.
PatchAssessmentResources
| where type has 'softwarepatches' and properties has 'version'
| extend machineName = tostring(split(id, '/', 8)), resourceType = tostring(split(type, '/', 0)), tostring(rgName = split(id, '/', 4)), tostring(RunID = split(id, '/', 10))
| extend prop = parse_json(properties)
| extend lTime = todatetime(prop.lastModifiedDateTime), patchName = tostring(prop.patchName), version = tostring(prop.version), installationState = tostring(prop.installationState), classifications = tostring(prop.classifications)
| where lTime > ago(7d)
| project lTime, RunID, machineName, rgName, resourceType, patchName, version, classifications, installationState
| sort by RunID
az graph query -q "PatchAssessmentResources | where type has 'softwarepatches' and properties has 'version' | extend machineName = tostring(split(id, '/', 8)), resourceType = tostring(split(type, '/', 0)), tostring(rgName = split(id, '/', 4)), tostring(RunID = split(id, '/', 10)) | extend prop = parse_json(properties) | extend lTime = todatetime(prop.lastModifiedDateTime), patchName = tostring(prop.patchName), version = tostring(prop.version), installationState = tostring(prop.installationState), classifications = tostring(prop.classifications) | where lTime > ago(7d) | project lTime, RunID, machineName, rgName, resourceType, patchName, version, classifications, installationState | sort by RunID"
Kaynak kimliklerine göre sanal makinelerin ve ilişkili kullanılabilirlik durumlarının listesi
Kullanılabilirlik durumuna göre toplanan sanal makinelerin (tür Microsoft.Compute/virtualMachines
) en son listesini döndürür. Sorgu ayrıca, kolay hata ayıklama ve azaltma için temelinde properties.targetResourceId
ilişkili kaynak kimliğini sağlar. Kullanılabilirlik durumları dört değerden biri olabilir: Kullanılabilir, Kullanılamıyor, Düzeyi Düşürülmüş ve Bilinmiyor. Kullanılabilirlik durumlarının her biri hakkında daha fazla bilgi için bkz. Azure Kaynak Durumu genel bakış.
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)"
Kaynak Kimlikleri ve kaynak Grupları ile kullanılabilirlik durumuna ve güç durumuna göre sanal makinelerin listesi
Sanal makineleriniz için uyumlu bir sistem durumu sağlamak üzere güç durumlarına ve kullanılabilirlik durumlarına göre toplanan sanal makinelerin (tür Microsoft.Compute/virtualMachines
) listesini döndürür. Sorgu ayrıca, kaynaklarınıza ilişkin ayrıntılı görünürlük için her girişle ilişkili kaynak grubu ve kaynak kimliğiyle ilgili ayrıntılar sağlar.
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'"
Kaynak Kimliklerine Göre Kullanılabilir Olmayan Sanal Makinelerin Listesi
Kullanılabilirlik durumlarına göre toplanan sanal makinelerin (tür Microsoft.Compute/virtualMachines
) en son listesini döndürür. Doldurulan liste yalnızca kullanılabilirlik durumu Kullanılabilir olmayan sanal makineleri vurgular ve sanal makinelerinizin içinde olduğu tüm ilgili durumların farkında olduğunuzdan emin olun. Tüm sanal makineleriniz Kullanılabilir olduğunda hiçbir sonuç almayı bekleyebilirsiniz.
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)"
Yapılan Windows Server işletim sistemi güncelleştirme yüklemesinin listesi
Son yedi gün içinde makineleriniz için yapılan Windows Server - İşletim sistemi güncelleştirme yükleme çalıştırmalarının durumunun listesini döndürür.
PatchAssessmentResources
| where type has 'softwarepatches' and properties !has 'version'
| extend machineName = tostring(split(id, '/', 8)), resourceType = tostring(split(type, '/', 0)), tostring(rgName = split(id, '/', 4)), tostring(RunID = split(id, '/', 10))
| extend prop = parse_json(properties)
| extend lTime = todatetime(prop.lastModifiedDateTime), patchName = tostring(prop.patchName), kbId = tostring(prop.kbId), installationState = tostring(prop.installationState), classifications = tostring(prop.classifications)
| where lTime > ago(7d)
| project lTime, RunID, machineName, rgName, resourceType, patchName, kbId, classifications, installationState
| sort by RunID
az graph query -q "PatchAssessmentResources | where type has 'softwarepatches' and properties !has 'version' | extend machineName = tostring(split(id, '/', 8)), resourceType = tostring(split(type, '/', 0)), tostring(rgName = split(id, '/', 4)), tostring(RunID = split(id, '/', 10)) | extend prop = parse_json(properties) | extend lTime = todatetime(prop.lastModifiedDateTime), patchName = tostring(prop.patchName), kbId = tostring(prop.kbId), installationState = tostring(prop.installationState), classifications = tostring(prop.classifications) | where lTime > ago(7d) | project lTime, RunID, machineName, rgName, resourceType, patchName, kbId, classifications, installationState | sort by RunID"
Sanal makineleri ağ arabirimi ve genel IP ile listeleme
Bu sorgu, Resource Manager dağıtım modeliyle oluşturulan sanal makineleri, ilgili ağ arabirimlerini ve bu ağ arabirimleriyle ilgili tüm genel IP adreslerini bir araya getirmek için iki leftouter
join
komut kullanır.
Resources
| where type =~ 'microsoft.compute/virtualmachines'
| extend nics=array_length(properties.networkProfile.networkInterfaces)
| mv-expand nic=properties.networkProfile.networkInterfaces
| where nics == 1 or nic.properties.primary =~ 'true' or isempty(nic)
| project vmId = id, vmName = name, vmSize=tostring(properties.hardwareProfile.vmSize), nicId = tostring(nic.id)
| join kind=leftouter (
Resources
| where type =~ 'microsoft.network/networkinterfaces'
| extend ipConfigsCount=array_length(properties.ipConfigurations)
| mv-expand ipconfig=properties.ipConfigurations
| where ipConfigsCount == 1 or ipconfig.properties.primary =~ 'true'
| project nicId = id, publicIpId = tostring(ipconfig.properties.publicIPAddress.id))
on nicId
| project-away nicId1
| summarize by vmId, vmName, vmSize, nicId, publicIpId
| join kind=leftouter (
Resources
| where type =~ 'microsoft.network/publicipaddresses'
| project publicIpId = id, publicIpAddress = properties.ipAddress)
on publicIpId
| project-away publicIpId1
az graph query -q "Resources | where type =~ 'microsoft.compute/virtualmachines' | extend nics=array_length(properties.networkProfile.networkInterfaces) | mv-expand nic=properties.networkProfile.networkInterfaces | where nics == 1 or nic.properties.primary =~ 'true' or isempty(nic) | project vmId = id, vmName = name, vmSize=tostring(properties.hardwareProfile.vmSize), nicId = tostring(nic.id) | join kind=leftouter ( Resources | where type =~ 'microsoft.network/networkinterfaces' | extend ipConfigsCount=array_length(properties.ipConfigurations) | mv-expand ipconfig=properties.ipConfigurations | where ipConfigsCount == 1 or ipconfig.properties.primary =~ 'true' | project nicId = id, publicIpId = tostring(ipconfig.properties.publicIPAddress.id)) on nicId | project-away nicId1 | summarize by vmId, vmName, vmSize, nicId, publicIpId | join kind=leftouter ( Resources | where type =~ 'microsoft.network/publicipaddresses' | project publicIpId = id, publicIpAddress = properties.ipAddress) on publicIpId | project-away publicIpId1"
İsme göre sıralanmış tüm sanal makineleri azalan düzende göster
Yalnızca sanal makineleri (Microsoft.Compute/virtualMachines
türündeki) listelemek için sonuçlarda type özelliğini eşleştirebiliriz. Önceki sorguya benzer şekilde desc
, order by
’yi azalan olması için değiştirir. Eşleme türündeki =~
, Kaynak Grafiği’nin büyük/küçük harfe duyarlı olmadığını bildirir.
Resources
| project name, location, type
| where type =~ 'Microsoft.Compute/virtualMachines'
| order by name desc
az graph query -q "Resources | project name, location, type | where type =~ 'Microsoft.Compute/virtualMachines' | order by name desc"
Ada ve işletim sistemi türüne göre ilk beş sanal makineyi gösterme
Bu sorgu yalnızca ada göre sıralanmış beş eşleşen kaydı almak için kullanır top
. Azure kaynağının türü Microsoft.Compute/virtualMachines
’dir. project
, Azure Kaynak Grafiği’ne hangi özelliklerin dahil edileceğini bildirir.
Resources
| where type =~ 'Microsoft.Compute/virtualMachines'
| project name, properties.storageProfile.osDisk.osType
| top 5 by name desc
az graph query -q "Resources | where type =~ 'Microsoft.Compute/virtualMachines' | project name, properties.storageProfile.osDisk.osType | top 5 by name desc"
Sanal makineyi güç durumlarının genişletilmiş özelliğine göre özetleme
Bu sorgu, güç durumlarına göre özetlemek için sanal makinelerdeki genişletilmiş özellikleri kullanır.
Resources
| where type == 'microsoft.compute/virtualmachines'
| summarize count() by tostring(properties.extended.instanceView.powerState.code)
az graph query -q "Resources | where type == 'microsoft.compute/virtualmachines' | summarize count() by tostring(properties.extended.instanceView.powerState.code)"
Normal ifade tarafından eşleştirilen sanal makineler
Bu sorgu, normal ifadeyle (regex olarak bilinir) eşleşen sanal makineleri arar. regex @ ile eşleşir, eşleşmesi gereken regex değerini tanımlamamıza olanak tanır.^Contoso(.*)[0-9]+$
Bu normal ifade tanımı şöyle açıklanmıştır:
^
- Eşleşme dizenin başında başlamalıdır.Contoso
- Büyük/küçük harfe duyarlı dize.(.*)
- Alt ifade eşleşmesi:.
- Herhangi bir tek karakterle eşleşir (yeni bir satır hariç).*
- Önceki öğeyle sıfır veya daha fazla kez eşleşir.
[0-9]
- 0’dan 9’a kadar olan sayılar için karakter grubu eşleşmesi.+
- Önceki öğeyle bir veya daha fazla kez eşleşir.$
- Önceki öğenin eşleşmesi dizenin sonunda gerçekleşmelidir.
Ada göre eşleşmeden sonra sorgu, adı ve siparişleri ada göre artan şekilde yansıtır.
Resources
| where type =~ 'microsoft.compute/virtualmachines' and name matches regex @'^Contoso(.*)[0-9]+$'
| project name
| order by name asc
az graph query -q "Resources | where type =~ 'microsoft.compute/virtualmachines' and name matches regex @'^Contoso(.*)[0-9]+\$' | project name | order by name asc"
Sonraki adımlar
- Sorgu dili hakkında daha fazla bilgi edinin.
- Kaynakları keşfetme hakkında daha fazla bilgi edinin.