az costmanagement
Manage cost and billing in Azure.
Commands
az costmanagement export |
Costmanagement export. |
az costmanagement export create |
The operation to create an export. |
az costmanagement export delete |
The operation to delete an export. |
az costmanagement export list |
The operation to list all exports at the given scope. |
az costmanagement export show |
The operation to get the execution history of an export for the defined scope by export name. |
az costmanagement export update |
The operation to update an export. |
az costmanagement query |
Query the usage data for scope defined. |
az costmanagement query
Query the usage data for scope defined.
az costmanagement query --scope
--timeframe {BillingMonthToDate, Custom, MonthToDate, TheLastBillingMonth, TheLastMonth, WeekToDate}
--type {ActualCost, AmortizedCost, Usage}
[--dataset-aggregation]
[--dataset-configuration]
[--dataset-filter]
[--dataset-grouping]
[--time-period]
Examples
Query in ManagementGroup scope
az costmanagement query --type "Usage" --dataset-filter "{\"and\":[{\"or\":[{\"dimension\":{\"name\":\"ResourceLocation\",\"operator\":\"In\",\"values\":[\"East US\",\"West Europe\"]}},{\"tag\":{\"name\":\"Environment\",\"operator\":\"In\",\"values\":[\"UAT\",\"Prod\"]}}]},{\"dimension\":{\"name\":\"ResourceGroup\",\"operator\":\"In\",\"values\":[\"API\"]}}]}" --timeframe "MonthToDate" --scope "providers/Microsoft.Management/managementGroups/MyMgId"
Query in ManagementGroupQuery scope via grouping
az costmanagement query --type "Usage" --dataset-aggregation "{\"totalCost\":{\"name\":\"PreTaxCost\",\"function\":\"Sum\"}}" --dataset-grouping name="ResourceGroup" type="Dimension" --timeframe "TheLastMonth" --scope "providers/Microsoft.Management/managementGroups/MyMgId"
Query in a ResourceGroup scope
az costmanagement query --type "Usage" --dataset-filter "{\"and\":[{\"or\":[{\"dimension\":{\"name\":\"ResourceLocation\",\"operator\":\"In\",\"values\":[\"East US\",\"West Europe\"]}},{\"tag\":{\"name\":\"Environment\",\"operator\":\"In\",\"values\":[\"UAT\",\"Prod\"]}}]},{\"dimension\":{\"name\":\"ResourceGroup\",\"operator\":\"In\",\"values\":[\"API\"]}}]}" --timeframe "MonthToDate" --scope "subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/ScreenSharingTest-peer"
Query in a ResourceGroupQuery scope via grouping
az costmanagement query --type "Usage" --dataset-aggregation "{\"totalCost\":{\"name\":\"PreTaxCost\",\"function\":\"Sum\"}}" --dataset-grouping name="ResourceType" type="Dimension" --timeframe "TheLastMonth" --scope "subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/ScreenSharingTest-peer"
Query in a Subscription scope
az costmanagement query --type "Usage" --dataset-filter "{\"and\":[{\"or\":[{\"dimension\":{\"name\":\"ResourceLocation\",\"operator\":\"In\",\"values\":[\"East US\",\"West Europe\"]}},{\"tag\":{\"name\":\"Environment\",\"operator\":\"In\",\"values\":[\"UAT\",\"Prod\"]}}]},{\"dimension\":{\"name\":\"ResourceGroup\",\"operator\":\"In\",\"values\":[\"API\"]}}]}" --timeframe "MonthToDate" --scope "subscriptions/00000000-0000-0000-0000-000000000000"
Query in a Subscription scope via grouping
az costmanagement query --type "Usage" --dataset-aggregation "{\"totalCost\":{\"name\":\"PreTaxCost\",\"function\":\"Sum\"}}" --dataset-grouping name="ResourceGroup" type="Dimension" --timeframe "TheLastMonth" --scope "subscriptions/00000000-0000-0000-0000-000000000000"
Required Parameters
The scope associated with query and export operations. This includes "/subscriptions/{subscriptionId}/" for subscription scope, "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}" for resourceGroup scope, "/providers/Microsoft.Management/managementGroups/{managementGroupId}" for Management Group scope.
The time frame for pulling data for the query.If custom, then a specific time period must be provided.
The type of the query.
Optional Parameters
Dictionary of aggregation expression to use in the query. The key of each item in the dictionary is the aliasfor the aggregated column. Query can have up to 2 aggregation clauses. Expected value: json-string/@json-file.
Has configuration information for the data in the export. The configuration will be ignored if aggregation and grouping are provided. Expect value: columns=xx.
Has filter expression to use in the query. Expected value: json-string/@json-file.
Array of group by expression to use in the query. Query can have up to 2 group by clauses.Expect value: KEY1=VALUE1 KEY2=VALUE2 ... , available KEYs are: type, name.
Has time period for pulling data for the query. Expect value: from=TIMESTAMP1 to=TIMESTAMP2. The timestamp format is like 2020-05-01T00:00:00.
Increase logging verbosity to show all debug logs.
Show this help message and exit.
Only show errors, suppressing warnings.
Output format.
JMESPath query string. See http://jmespath.org/ for more information and examples.
Increase logging verbosity. Use --debug for full debug logs.