Skip to content

Commit 6461629

Browse files
committed
New sample: Cost summary from Azure Advisor
1 parent 075cd32 commit 6461629

File tree

1 file changed

+48
-2
lines changed
  • articles/governance/resource-graph/samples

1 file changed

+48
-2
lines changed

articles/governance/resource-graph/samples/starter.md

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Starter query samples
33
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
55
ms.topic: sample
66
---
77
# Starter Resource Graph query samples
@@ -29,6 +29,7 @@ We'll walk through the following starter queries:
2929
> - [Show aliases for a virtual machine resource](#show-aliases)
3030
> - [Show distinct values for a specific alias](#distinct-alias-values)
3131
> - [Show unassociated network security groups](#unassociated-nsgs)
32+
> - [Get cost savings summary from Azure Advisor](#advisor-savings)
3233
3334
If you don't have an Azure subscription, create a [free account](https://azure.microsoft.com/free) before you begin.
3435

@@ -562,7 +563,8 @@ Search-AzGraph -Query "Resources | where type=~'Microsoft.Compute/virtualMachine
562563

563564
## <a name="unassociated-nsgs" />Show unassociated network security groups
564565

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.
566568

567569
```kusto
568570
Resources
@@ -593,6 +595,50 @@ Search-AzGraph -Query "Resources | where type =~ 'microsoft.network/networksecur
593595

594596
---
595597

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+
![Resource Graph explorer icon](../media/resource-graph-small.png) 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> ![Open link in new window icon](../../media/new-window.png)
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> ![Open link in new window icon](../../media/new-window.png)
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> ![Open link in new window icon](../../media/new-window.png)
639+
640+
---
641+
596642
## Next steps
597643

598644
- Learn more about the [query language](../concepts/query-language.md).

0 commit comments

Comments
 (0)