At Ignite 2018, Microsoft announced the availability of Azure Resource Graph. Link to Docs
So whats it all about ?
When running IT in Azure, it is sometimes necessary to know details from your Azure Resources and you typically query it via PowerShell, the CLI or the REST API directly.
Microsoft has figured out heavy load on their REST-API as people need to get information about their cloud-infrastructure very often. So what they did with Resource Graph is to create a cached version and provide the data via an Azure Serivice named Azure Data Explorer.
So lets make some experiments if this is really faster. I am using PowerShell Core 6.1 and the Az.* Modules. After logging in you my target subscription, i can do some tests.
Resource Graph – List all resources
1 2 |
(measure-command -expression {Search-AzGraph -Query 'summarize count()'}).totalmilliseconds PS > 2161,6949 |
Resource Manager – List all resources
1 2 |
(measure-command -expression {(get-azresource).count}).totalmilliseconds PS> 688 |
AHA ! – why is that ? Resource Graph is slower ? Well, you may have experienced this as well, there must be some caching mechanism in the REST-API also. Whenever you do the same query the SECOND time, its much faster.
So maybe performance is not the main issue, just put the load away from the REST-API. Lets try some other examples from MS Docs.
1 2 3 4 5 |
#List all Resources and show name, type and location Search-AzGraph -Query 'project name, type,location' #List only VM´s (filter by Provider/Type) Search-AzureRmGraph -Query "project name, location, type| where type =~ 'Microsoft.Compute/virtualMachines' | order by name desc" |
Resource Graph provides richer data
Now lets compare the output for one VM between Graph and ARM
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
#ARM provides this Get-AzResource -Name SampleLinuxBox|Convertto-Json { "ResourceId": "/subscriptions/00000000-aaaa-bbbb-cccc-111111111111/resourceGroups/P42Compute2/providers/Microsoft.Compute/virtualMachines/SampleLinuxBox", "Id": "/subscriptions/00000000-aaaa-bbbb-cccc-111111111111/resourceGroups/P42Compute2/providers/Microsoft.Compute/virtualMachines/SampleLinuxBox", "Identity": null, "Kind": null, "Location": "westeurope", "ManagedBy": null, "Name": "SampleLinuxBox", "ParentResource": null, "Plan": null, "Properties": null, "ResourceGroupName": "P42Compute2", "ResourceType": "Microsoft.Compute/virtualMachines", "Sku": null, "Tags": { "PCC-EntityId": "123" }, "Type": "Microsoft.Compute/virtualMachines" } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
#Resource Graph provides fundamentially more information<br>Search-AzGraph -Query "where type =~ 'Microsoft.Compute/virtualMachines' | where name =~ 'SampleLinuxBox'"|convertto-JSON<br><br>{<br> "type": "microsoft.compute/virtualmachines",<br> "name": "SampleLinuxBox",<br> "id": "/subscriptions/00000000-aaaa-bbbb-cccc-111111111111/resourceGroups/P42Compute2/providers/Microsoft.Compute/virtualMachines/SampleLinuxBox",<br> "sku": {},<br> "kind": "",<br> "plan": {},<br> "tags": {<br> "PCC-EntityId": "123"<br> },<br> "aliases": {<br> "Microsoft.Compute/virtualMachines/osProfile.linuxConfiguration.disablePasswordAuthentication": false,<br> "Microsoft.Compute/virtualMachines/storageProfile.dataDisks[<em>].managedDisk.storageAccountType": [], "Microsoft.Compute/virtualMachines/osProfile.windowsConfiguration.enableAutomaticUpdates": null, "Microsoft.Compute/virtualMachines/storageProfile.osDisk.managedDisk.storageAccountType": "Standard_LRS", "Microsoft.Compute/virtualMachines/storageProfile.osDisk.encryptionSettings.enabled": null, "Microsoft.Compute/virtualMachines/osProfile.windowsConfiguration.provisionVMAgent": null, "Microsoft.Compute/virtualMachines/diagnosticsProfile.bootDiagnostics.storageUri": "https://p42compute1diag906.blob.core.windows.net/", "Microsoft.Compute/virtualMachines/storageProfile.dataDisks[</em>].managedDisk.id": [],<br> "Microsoft.Compute/virtualMachines/diagnosticsProfile.bootDiagnostics.enabled": true,<br> "Microsoft.Compute/virtualMachines/storageProfile.osDisk.encryptionSettings": null,<br> "Microsoft.Compute/virtualMachines/storageProfile.dataDisks[<em>].createOption": [], "Microsoft.Compute/virtualMachines/storageProfile.dataDisks[</em>].diskSizeGB": [],<br> "Microsoft.Compute/virtualMachines/storageProfile.dataDisks[<em>].image.uri": [], "Microsoft.Compute/virtualMachines/storageProfile.osDisk.managedDisk.id": "/subscriptions/98c62a48-2b63-4796-9015-176b9fb173f2/resourceGroups/P42Compute2/providers/Microsoft.Compute/disks/SampleLinuxBox_OsDisk_1_5efb93db6597414c95abf359a4777d34", "Microsoft.Compute/virtualMachines/storageProfile.dataDisks[</em>].vhd.uri": [],<br> "Microsoft.Compute/virtualMachines/storageProfile.dataDisks[<em>].caching": [], "Microsoft.Compute/virtualMachines/diagnosticsProfile.bootDiagnostics": { "storageUri": "https://p42compute1diag906.blob.core.windows.net/", "enabled": true }, "Microsoft.Compute/virtualMachines/storageProfile.osDisk.createOption": "FromImage", "Microsoft.Compute/virtualMachines/storageProfile.dataDisks[</em>].name": [],<br> "Microsoft.Compute/virtualMachines/storageProfile.dataDisks[<em>].lun": [], "Microsoft.Compute/virtualMachines/osProfile.windowsConfiguration": null, "Microsoft.Compute/virtualMachines/storageProfile.osDisk.caching": "ReadWrite", "Microsoft.Compute/virtualMachines/storageProfile.osDisk.vhd.uri": null, "Microsoft.Compute/virtualMachines/storageProfile.osDisk.osType": "Linux", "Microsoft.Compute/virtualMachines/osProfile.linuxConfiguration": { "disablePasswordAuthentication": false }, "Microsoft.Compute/virtualMachines/storageProfile.osDisk.name": "SampleLinuxBox_OsDisk_1_5efb93db6597414c95abf359a4777d34", "Microsoft.Compute/imagePublisher": "Canonical", "Microsoft.Compute/virtualMachines/storageProfile.osDisk.vhd": null, "Microsoft.Compute/virtualMachines/networkInterfaces[</em>].id": [<br> "/subscriptions/98c62a48-2b63-4796-9015-176b9fb173f2/resourceGroups/P42Compute2/providers/Microsoft.Network/networkInterfaces/samplelinuxbox891"<br> ],<br> "Microsoft.Compute/virtualMachines/osProfile.adminPassword": null,<br> "Microsoft.Compute/virtualMachines/osProfile.adminUsername": "cloudint",<br> "Microsoft.Compute/imageVersion": "latest",<br> "Microsoft.Compute/virtualMachines/availabilitySet.id": null,<br> "Microsoft.Compute/imageOffer": "UbuntuServer",<br> "Microsoft.Compute/imageSku": "16.04-LTS",<br> "Microsoft.Compute/virtualMachines/imagePublisher": "Canonical",<br> "Microsoft.Compute/imageId": null,<br> "Microsoft.Compute/virtualMachines/imageVersion": "latest",<br> "Microsoft.Compute/virtualMachines/imageOffer": "UbuntuServer",<br> "Microsoft.Compute/virtualMachines/osDisk.Uri": null,<br> "Microsoft.Compute/virtualMachines/sku.name": "Basic_A2",<br> "Microsoft.Compute/virtualMachines/imageSku": "16.04-LTS",<br> "Microsoft.Compute/licenseType": null<br> },<br> "location": "westeurope",<br> "properties": {<br> "provisioningState": "Succeeded",<br> "storageProfile": {<br> "imageReference": "@{version=latest; publisher=Canonical; sku=16.04-LTS; offer=UbuntuServer}",<br> "dataDisks": "",<br> "osDisk": "@{name=SampleLinuxBox_OsDisk_1_5efb93db6597414c95abf359a4777d34; createOption=FromImage; diskSizeGB=30; caching=ReadWrite; managedDisk=; osType=Linux}"<br> },<br> "hardwareProfile": {<br> "vmSize": "Basic_A2"<br> },<br> "networkProfile": {<br> "networkInterfaces": ""<br> },<br> "osProfile": {<br> "adminUsername": "cloudint",<br> "computerName": "SampleLinuxBox",<br> "linuxConfiguration": "@{disablePasswordAuthentication=False}",<br> "secrets": ""<br> },<br> "diagnosticsProfile": {<br> "bootDiagnostics": "@{enabled=True; storageUri=https://p42compute1diag906.blob.core.windows.net/}"<br> },<br> "vmId": "29a9ed57-748c-4616-881e-50ceee015b1a"<br> },<br> "resourceGroup": "p42compute2",<br> "subscriptionId": "00000000-aaaa-bbbb-cccc-111111111111",<br> "managedBy": "",<br> "identity": {},<br> "ResourceId": "/subscriptions/00000000-aaaa-bbbb-cccc-111111111111/resourceGroups/P42Compute2/providers/Microsoft.Compute/virtualMachines/SampleLinuxBox"<br> }<br><br> |
So what we learned is that Resource Graph shows more and better structured information that the REST-API. The Query Language makes it also interesting, because you can easily define your own queries which allows pre-filtering of information.
Go try something of this and wait for part 2 on this article.