|
1 | 1 | ---
|
2 | 2 | title: Starter query samples
|
3 | 3 | description: Use Azure Resource Graph to run some starter queries, including counting resources, ordering resources, or by a specific tag.
|
4 |
| -ms.date: 11/21/2019 |
| 4 | +ms.date: 04/27/2020 |
5 | 5 | ms.topic: sample
|
6 | 6 | ---
|
7 | 7 | # Starter Resource Graph query samples
|
@@ -29,6 +29,7 @@ We'll walk through the following starter queries:
|
29 | 29 | > - [Show aliases for a virtual machine resource](#show-aliases)
|
30 | 30 | > - [Show distinct values for a specific alias](#distinct-alias-values)
|
31 | 31 | > - [Show unassociated network security groups](#unassociated-nsgs)
|
| 32 | +> - [Get cost savings summary from Azure Advisor](#advisor-savings) |
32 | 33 |
|
33 | 34 | If you don't have an Azure subscription, create a [free account](https://azure.microsoft.com/free) before you begin.
|
34 | 35 |
|
@@ -562,7 +563,8 @@ Search-AzGraph -Query "Resources | where type=~'Microsoft.Compute/virtualMachine
|
562 | 563 |
|
563 | 564 | ## <a name="unassociated-nsgs" />Show unassociated network security groups
|
564 | 565 |
|
565 |
| -This query returns Network Security Groups (NSGs) that aren't associated to a network interface or subnet. |
| 566 | +This query returns Network Security Groups (NSGs) that aren't associated to a network interface or |
| 567 | +subnet. |
566 | 568 |
|
567 | 569 | ```kusto
|
568 | 570 | Resources
|
@@ -593,6 +595,50 @@ Search-AzGraph -Query "Resources | where type =~ 'microsoft.network/networksecur
|
593 | 595 |
|
594 | 596 | ---
|
595 | 597 |
|
| 598 | +## <a name="advisor-savings" />Get cost savings summary from Azure Advisor |
| 599 | + |
| 600 | +This query summarizes the cost savings of each |
| 601 | +[Azure Advisor](../../../advisor/advisor-overview.md) recommendation. |
| 602 | + |
| 603 | +```kusto |
| 604 | +advisorresources |
| 605 | +| where type == 'microsoft.advisor/recommendations' |
| 606 | +| where properties.category == 'Cost' |
| 607 | +| extend |
| 608 | + resources = tostring(properties.resourceMetadata.resourceId), |
| 609 | + savings = todouble(properties.extendedProperties.savingsAmount), |
| 610 | + solution = tostring(properties.shortDescription.solution), |
| 611 | + currency = tostring(properties.extendedProperties.savingsCurrency) |
| 612 | +| summarize |
| 613 | + dcount(resources), |
| 614 | + bin(sum(savings), 0.01) |
| 615 | + by solution, currency |
| 616 | +| project solution, dcount_resources, sum_savings, currency |
| 617 | +| order by sum_savings desc |
| 618 | +``` |
| 619 | + |
| 620 | +# [Azure CLI](#tab/azure-cli) |
| 621 | + |
| 622 | +```azurecli-interactive |
| 623 | +az graph query -q "advisorresources | where type == 'microsoft.advisor/recommendations' | where properties.category == 'Cost' | extend resources = tostring(properties.resourceMetadata.resourceId), savings = todouble(properties.extendedProperties.savingsAmount), solution = tostring(properties.shortDescription.solution), currency = tostring(properties.extendedProperties.savingsCurrency) | summarize dcount(resources), bin(sum(savings), 0.01) by solution, currency | project solution, dcount_resources, sum_savings, currency | order by sum_savings desc" |
| 624 | +``` |
| 625 | + |
| 626 | +# [Azure PowerShell](#tab/azure-powershell) |
| 627 | + |
| 628 | +```azurepowershell-interactive |
| 629 | +Search-AzGraph -Query "advisorresources | where type == 'microsoft.advisor/recommendations' | where properties.category == 'Cost' | extend resources = tostring(properties.resourceMetadata.resourceId), savings = todouble(properties.extendedProperties.savingsAmount), solution = tostring(properties.shortDescription.solution), currency = tostring(properties.extendedProperties.savingsCurrency) | summarize dcount(resources), bin(sum(savings), 0.01) by solution, currency | project solution, dcount_resources, sum_savings, currency | order by sum_savings desc" |
| 630 | +``` |
| 631 | + |
| 632 | +# [Portal](#tab/azure-portal) |
| 633 | + |
| 634 | + Try this query in Azure Resource Graph Explorer: |
| 635 | + |
| 636 | +- Azure portal: <a href="https://portal.azure.com/?feature.customportal=false#blade/HubsExtension/ArgQueryBlade/query/advisorresources%20%7C%20where%20type%20%3D%3D%20%27microsoft.advisor%2Frecommendations%27%20%7C%20where%20properties.category%20%3D%3D%20%27Cost%27%20%7C%20extend%20resources%20%3D%20tostring%28properties.resourceMetadata.resourceId%29%2C%20savings%20%3D%20todouble%28properties.extendedProperties.savingsAmount%29%2C%20solution%20%3D%20tostring%28properties.shortDescription.solution%29%2C%20currency%20%3D%20tostring%28properties.extendedProperties.savingsCurrency%29%20%7C%20summarize%20dcount%28resources%29%2C%20bin%28sum%28savings%29%2C%200.01%29%20by%20solution%2C%20currency%20%7C%20project%20solution%2C%20dcount_resources%2C%20sum_savings%2C%20currency%20%7C%20order%20by%20sum_savings%20desc" target="_blank">portal.azure.com</a>  |
| 637 | +- Azure Government portal: <a href="https://portal.azure.us/?feature.customportal=false#blade/HubsExtension/ArgQueryBlade/query/advisorresources%20%7C%20where%20type%20%3D%3D%20%27microsoft.advisor%2Frecommendations%27%20%7C%20where%20properties.category%20%3D%3D%20%27Cost%27%20%7C%20extend%20resources%20%3D%20tostring%28properties.resourceMetadata.resourceId%29%2C%20savings%20%3D%20todouble%28properties.extendedProperties.savingsAmount%29%2C%20solution%20%3D%20tostring%28properties.shortDescription.solution%29%2C%20currency%20%3D%20tostring%28properties.extendedProperties.savingsCurrency%29%20%7C%20summarize%20dcount%28resources%29%2C%20bin%28sum%28savings%29%2C%200.01%29%20by%20solution%2C%20currency%20%7C%20project%20solution%2C%20dcount_resources%2C%20sum_savings%2C%20currency%20%7C%20order%20by%20sum_savings%20desc" target="_blank">portal.azure.us</a>  |
| 638 | +- Azure China portal: <a href="https://portal.azure.cn/?feature.customportal=false#blade/HubsExtension/ArgQueryBlade/query/advisorresources%20%7C%20where%20type%20%3D%3D%20%27microsoft.advisor%2Frecommendations%27%20%7C%20where%20properties.category%20%3D%3D%20%27Cost%27%20%7C%20extend%20resources%20%3D%20tostring%28properties.resourceMetadata.resourceId%29%2C%20savings%20%3D%20todouble%28properties.extendedProperties.savingsAmount%29%2C%20solution%20%3D%20tostring%28properties.shortDescription.solution%29%2C%20currency%20%3D%20tostring%28properties.extendedProperties.savingsCurrency%29%20%7C%20summarize%20dcount%28resources%29%2C%20bin%28sum%28savings%29%2C%200.01%29%20by%20solution%2C%20currency%20%7C%20project%20solution%2C%20dcount_resources%2C%20sum_savings%2C%20currency%20%7C%20order%20by%20sum_savings%20desc" target="_blank">portal.azure.cn</a>  |
| 639 | + |
| 640 | +--- |
| 641 | + |
596 | 642 | ## Next steps
|
597 | 643 |
|
598 | 644 | - Learn more about the [query language](../concepts/query-language.md).
|
|
0 commit comments