Skip to content

Commit f9ec72b

Browse files
authored
Merge pull request #49717 from rloutlaw/rloutlaw/cost-mgmt
change up to cost mgmt api for the billing examples
2 parents 567a6a9 + 71c2408 commit f9ec72b

File tree

1 file changed

+97
-75
lines changed

1 file changed

+97
-75
lines changed

articles/billing/billing-review-service-usage-api.md

Lines changed: 97 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,24 @@ ms.author: alleonar
2020

2121
# Review Azure resource usage using the REST API
2222

23+
Azure Cost Management APIs help you review and manage consumption of your Azure resources.
2324

24-
Azure [Consumption APIs](https://docs.microsoft.com/rest/api/consumption/) help you review the cost and usage data for your Azure resources.
25+
In this article, you learn how to create a daily report that will generate a comma-separated value document with your hourly usage information, and then how to use filters to customize the report so that you can query the usage of virtual machines, databases, and tagged resources in an Azure resource group.
2526

26-
In this article, you learn how to retrieve and aggregate resource usage information for resources in an Azure resource group, as well as how to filter these results based on [Azure resource manager tags](https://docs.microsoft.com/azure/azure-resource-manager/resource-group-using-tags).
27+
>[!NOTE]
28+
> The Cost Management API is currently in private preview.
2729
28-
## Get usage for a resource group
30+
## Create a basic cost management report
2931

30-
To get resource usage for compute, database, and other resources in a resource group, use the `usageDetails` REST operation and filter the results by resource group.
32+
Use the `reports` operation in the Cost Management API to define how the cost reporting is generated and where the reports will be published to.
3133

3234
```http
33-
https://management.azure.com/subscriptions/{subscription-id}/providers/Microsoft.Consumption/usageDetails?api-version=2018-06-30&filter=properties/resourceGroup eq '{resource-group}]
35+
https://management.azure.com/subscriptions/{subscriptionGuid}/providers/Microsoft.CostManagement/reports/{reportName}?api-version=2018-09-01-preview
3436
Content-Type: application/json
3537
Authorization: Bearer
3638
```
3739

38-
The `{subscription-id}` parameter is required and should contain a subscription ID that can access the {resource-group} resource group with a Reader role.
40+
The `{subscriptionGuid}` parameter is required and should contain a subscription ID that can be read using the credentials provieed in the API token. The `{reportName}`
3941

4042
The following headers are required:
4143

@@ -44,91 +46,111 @@ The following headers are required:
4446
|*Content-Type:*| Required. Set to `application/json`. |
4547
|*Authorization:*| Required. Set to a valid `Bearer` token. |
4648

47-
### Response
48-
49-
Status code 200 (OK) is returned for a successful response, which contains a list of usage statistics for each Azure resource in the resource group with subscriptipon ID `00000000-0000-0000-0000-000000000000`.
49+
Configure the parameters of the report in the HTTP request body. In the example below, the report is set to generate every day when active, is a CSV file written to an Azure Storage blob container, and contains hourly cost information for all resources in resource group `westus`.
5050

5151
```json
5252
{
53-
"value": [
54-
{
55-
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Billing/billingPeriods/201702/providers/Microsoft.Consumption/usageDetails/usageDetailsId1",
56-
"name": "usageDetailsId1",
57-
"type": "Microsoft.Consumption/usageDetails",
58-
"properties": {
59-
"billingPeriodId": "/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Billing/billingPeriods/201702",
60-
"invoiceId": "/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Billing/invoices/201703-123456789",
61-
"usageStart": "2017-02-13T00:00:00Z",
62-
"usageEnd": "2017-02-13T23:59:59Z",
63-
"instanceName": "shared1",
64-
"instanceId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resource-group/providers/Microsoft.Web/sites/shared1",
65-
"instanceLocation": "eastasia",
66-
"currency": "USD",
67-
"usageQuantity": 0.00328,
68-
"billableQuantity": 0.00328,
69-
"pretaxCost": 0.67,
70-
"isEstimated": false,
71-
"meterId": "00000000-0000-0000-0000-000000000000",
72-
"partNumber": "Part Number 1",
73-
"resourceGuid": "00000000-0000-0000-0000-000000000000",
74-
"offerId": "Offer Id 1",
75-
"chargesBilledSeparately": true,
76-
"location": "EU West"
77-
}
78-
} ] }
53+
"properties": {
54+
"schedule": {
55+
"status": "Inactive",
56+
"recurrence": "Daily",
57+
"recurrencePeriod": {
58+
"from": "2018-08-21",
59+
"to": "2019-10-31"
60+
}
61+
},
62+
"deliveryInfo": {
63+
"destination": {
64+
"resourceId": "/subscriptions/{subscriptionGuid}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{storageAccountName}",
65+
"container": "MyReportContainer",
66+
"rootFolderPath": "MyScheduleTest"
67+
}
68+
},
69+
"format": "Csv",
70+
"definition": {
71+
"type": "Usage",
72+
"timeframe": "MonthToDate",
73+
"dataSet": {
74+
"granularity": "Hourly",
75+
"filter": {
76+
"dimensions": {
77+
"name": "ResourceLocation",
78+
"operator": "In",
79+
"values": [
80+
"westus"
81+
]
82+
}
83+
}
84+
}
85+
}
86+
}
87+
}
7988
```
8089

81-
## Get usage for tagged resources
90+
The
8291

83-
To get resource usage for resources in organized by tags, use the `usageDetails` REST operation and filter the results by the tag name using the `$filter` query parameter.
92+
## Filtering reports
8493

85-
```http
86-
https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Consumption/usageDetails?$filter=tags eq 'tag1'&api-version=2018-06-30
87-
Content-Type: application/json
88-
Authorization: Bearer
94+
The `filter` and `dimensions` section of the request body when creating a report let you focus in on the costs for specific resource types. The previous request body shows how to filter by all resources in a region.
95+
96+
### Get all compute usage
97+
98+
Use the `ResourceType` dimension to report Azure virtual machine costs in your subscription across all regions.
99+
100+
```json
101+
"filter": {
102+
"dimensions": {
103+
"name": "ResourceType",
104+
"operator": "In",
105+
"values": [
106+
"Microsoft.ClassicCompute/virtualMachines",
107+
"Microsoft.Compute/virtualMachines"
108+
]
109+
}
110+
}
89111
```
90112

91-
The `{subscription-id}` parameter is required and should contain a subscription ID that can access the tagged resources.
113+
### Get all database usage
92114

115+
Use the `ResourceType` dimension to report Azure SQL Database costs in your subscription across all regions.
93116

94-
### Response
117+
```json
118+
"filter": {
119+
"dimensions": {
120+
"name": "ResourceType",
121+
"operator": "In",
122+
"values": [
123+
"Microsoft.Sql/servers"
124+
]
125+
}
126+
}
127+
```
95128

96-
Status code 200 (OK) is returned for a successful response, which contains a list of usage statistics for each Azure resource in the resource group with subscriptipon ID `00000000-0000-0000-0000-000000000000` and tag name key vault pair is `dev` and `tools`.
129+
### Report on specific instances
97130

98-
Sample response:
131+
The `Resource` dimension lets you report costs for specific resources.
99132

100133
```json
101-
{
102-
"value": [
103-
{
104-
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Billing/billingPeriods/201702/providers/Microsoft.Consumption/usageDetails/usageDetailsId1",
105-
"name": "usageDetailsId1",
106-
"type": "Microsoft.Consumption/usageDetails",
107-
"tags": {
108-
"dev": "tools"
109-
},
110-
"properties": {
111-
"billingPeriodId": "/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Billing/billingPeriods/201702",
112-
"invoiceId": "/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Billing/invoices/201703-123456789",
113-
"usageStart": "2017-02-13T00:00:00Z",
114-
"usageEnd": "2017-02-13T23:59:59Z",
115-
"instanceName": "shared1",
116-
"instanceId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/Default-Web-eastasia/providers/Microsoft.Web/sites/shared1",
117-
"instanceLocation": "eastasia",
118-
"currency": "USD",
119-
"usageQuantity": 0.00328,
120-
"billableQuantity": 0.00328,
121-
"pretaxCost": 0.67,
122-
"isEstimated": false,
123-
"meterId": "00000000-0000-0000-0000-000000000000",
124-
"partNumber": "Part Number 1",
125-
"resourceGuid": "00000000-0000-0000-0000-000000000000",
126-
"offerId": "Offer Id 1",
127-
"chargesBilledSeparately": true,
128-
"location": "EU West"
129-
}
134+
"filter": {
135+
"dimensions": {
136+
"name": "Resource",
137+
"operator": "In",
138+
"values": [
139+
"subscriptions/{subscriptionGuid}/resourceGroups/{resourceGroup}/providers/Microsoft.ClassicCompute/virtualMachines/{ResourceName}"
140+
]
130141
}
131-
]
142+
}
143+
```
144+
145+
### Changing timeframes
146+
147+
Set the `timeframe` definition to `Custom` to set a timeframe outside of the week to date and month to date bulit in options.
148+
149+
```json
150+
"timeframe": "Custom",
151+
"timePeriod": {
152+
"from": "2017-12-31T00:00:00.000Z",
153+
"to": "2018-12-30T00:00:00.000Z"
132154
}
133155
```
134156

0 commit comments

Comments
 (0)