Microsoft has announced the public preview release of two new Azure API’s.

  1. Azure Usage API
  2. Azure RateCard API

Using the above API’s customers and partners can programmatically access their Azure consumption and pricing details.

Azure Usage API :

With this REST API the customers and partners can get their usage data of their Azure subscription.  Using this API the customers and partners can access the Instance metadata (like resource uri,resource group info and resource tags) and Resource metadata(meter name, meter category, meter sub category, unit and region). Data can be accessed in “Hourly and Daily” Aggregations. By default it will be “Daily”

Azure RateCard API:

With this REST API the customers and partners can get the list of available resources along with estimated pricing information for each of the available resource.

Azure Usage Rest URL:

https://management.azure.com/subscriptions/{subscription-Id}/providers/Microsoft.Commerce/UsageAggregates?api-version={api-version}&reportedStartTime={dateTimeOffset-value}&reportedEndTime={dateTimeOffset-value}&aggregationGranularity={granularity-value}&showDetails={showdetail-boolean-Value}&continuationToken={token-value}

  • Set {dateTimeOffset-value} for reportedStartTime and reportedEndTime to valid dateTime values. Please note that this dateTimeOffset value represents the timestamp at which the resource usage was recorded within the Azure billing system
  • Set {aggregationGranularity} to either ‘Daily’ or ‘Hourly’. Default is daily.
  • Set {show Details} to either true or false. This is an optional Boolean flag, which can be configured to specify whether the caller wants instance-level details with the usage data. By default, this is set to true.
  • Set {continuation Token} to the continuation token string as retrieved from the response body in the previous call. This is the bookmark for progress when you are working with a large result set.

JSON Element Definitions :

Element Name Description
Id Unique Id for the usage aggregate.
name Name of the usage aggregate.
subscriptionId The subscription identifier for the Azure user.
meterId Unique ID for the resource that was consumed (aka ResourceID).
usageStartTime UTC start time for the usage bucket to which this usage aggregate belongs.
usageEndTime UTC end time for the usage bucket to which this usage aggregate belongs.
Quantity The amount of the resource consumption that occurred in this time frame.
Unit The unit in which the usage for this resource is being counted, e.g. Hours, GB.
meterName Friendly name of the resource being consumed.
meterCategory Category of the consumed resource.
meterSubCategory Sub-category of the consumed resource.
meterRegion Region of the meterId used for billing purposes.
infoFields Key-value pairs of instance details (legacy format).This field captures the key value pairs to store the instance level details in the legacy format. The most important item here is ‘Project’ because this carries the name of the instance provisioned by the user. If we spun up a website and called it “azuretestvm1”, the string “azuretestvm1” would show up as a value for Project for the website events for this website. For the resource metadata that is added in the info fields, please take a dependence on the higher level resource metadata (meterName, meterCategory, meterSubCategory, unit, meterRegion).
instanceData Key-value pairs of instance details (new format. See the FAQ section below for more details on the difference between the current infoFields design and the future instanceData design):·        resourceUri: This is the fully qualified resource ID, which includes the resource groups and the instance name.·        tags: Contains the resource tags specified by the user.·        location: The region in which this service was run.

·        additionalInfo: More details about the resource being consumed. For example, OS version, Image Type.

·        partNumber: Unique namespace used to identify the resource for Azure Marketplace 3rd party usage

·        orderNumber: Unique ID that represents the 3rd party order identifier. Presence of an orderNumber states that this usage record was incurred on a resource owned by a 3rd party and not Microsoft.

RateCard Rest URL :

https://management.azure.com/subscriptions/{subscription-Id}/providers/Microsoft.Commerce/RateCard?api-version={api-version}&$filter=OfferDurableId eq ’{OfferDurableId}’ and Currency eq ’{Currency}’ and Locale eq ’{Locale}’ and RegionInfo eq ’{RegionInfo}’’

  • Set {OfferDurableId} to a valid Offer ID code (e.g., MS-AZR-0026P). See Microsoft Azure Offer Details for more information on the list of available Offer IDs, country/region availability, and billing currency. The Offer ID parameter consists of the “MS-AZR-“ prefix, plus the Offer ID number.
  • Set {Currency} to the currency in which the resource rates need to be provided.
  • Set {Locale} to the culture in which the resource metadata needs to be localized.
  • Set {RegionInfo} to the 2 letter ISO code where the offer was purchased.

JSON Element Definitions for RateCard response body

Element Name Description
Credit The amount of credit provided under the terms of the given offer level. This field is used only by offer terms of type “Monetary Commitment”.
Currency The currency in which the rates are provided.
EffectiveDate Indicates the date from which the meter rate or offer term is effective.
ExcludedMeterIds An array of meter ids that are excluded from the given offer terms.
IncludedQuantity The resource quantity that is included in the offer at no cost. Consumption beyond this quantity will be charged.
IsTaxIncluded All rates are pretax, so this will always be returned as “false”.
Locale The culture in which the resource information is localized.
MeterCategory The category of the meter, e.g., “Cloud services”, “Networking”, etc..
MeterId The unique identifier of the resource.
MeterName The name of the meter, within the given meter category.
MeterRates The list of key/value pairs for the meter rates, in the format “key”:”value” where key = the meter quantity, and value = the corresponding price.
MeterRegion The region in which the Azure service is available.
MeterSubCategory The subcategory of the meter, e.g., “A6 Cloud services”, “ExpressRoute (IXP)”, etc..
Name The name of the Azure offer term, e.g., “Monetary Credit”.
ServiceRegion The region in which the Azure service is available.
Tags Provides additional meter data.“Third Party” indicates a meter with no discount. Blanks indicate First Party.
TieredDiscount The list of key/value pairs for the tiered meter rates, in the format “key”:”value” where key = price, and value = the corresponding discount percentage. This field is used only by offer terms of type “Monetary Commitment”.
Unit The unit in which the meter consumption is charged, e.g., “Hours”, “GB”, etc.

 

Customer can build custom dashboard using the Azure Public usage API.

Customers can use the Usage and RateCard APIs in combination to get better insights into their cloud spend during the month, by analyzing the hourly and daily buckets of usage and charge estimates.Also,with the concept of “Tags” in new portal, we can seperate the instances/resources based on the project.By using the concept of tags and these API’s we can estimate/get the details of Azure spend   on project/Application based.

In this blog, i am going to talk about how to calculate the price for the given project. All the resources in Azure mapped to Project using tags. For example(VM , web, Storage Account ….) are mapped to a particular project.Below is the screenshot of mapping a resource with name “ProjectA”.

AzureBilling

 

Example: The pricing data for Blob storage per GB per month is Rs.1.44. To calculate the project cost with the other resources,  i am using the Usage and RateCard Azure API’s.

Below is the code for making the call to RateCard API. Using the below API call, we can retrieve the pricing details for all the   resources of the azure.

CODE SAMPLE :

 Below is the code for making the call to UsageAPI based on the granularity(Daily/Hourly):

 

Below is the code to get the Authorization token.

 

Config Settings :