I am building an Azure Chargeback solution and for that I am pulling the Azure Usage data from Azure Billing REST APIs for multiple subscriptions and different dates. I need to store this into custom MS SQL database as per customer’s requirements. I get various usage records from Azure.
- Problem: From these Usage records, I am not able to find any combination of the columns in the data I receive which will give me a Unique Key to identify a Usage record for a particular subscription and for a specific date. Only column I see as different is Quantity but even that can be duplicated. E.g. If there are 2 VMs of type A1 with no data or applications on them, in the same cloud service, then they will have exact quantity of usage. I do not get the exact name of the VM or any other resource via the Usage APIs.
- One Custom Solution (Ineffective): I can append a counter or unique ID to the usage records but if I fetch the data next time the order may shuffle or new data may be introduced thereby affecting the logic for uniqueness. Any logic I build to checking if any data is missing in DB will result in bugs if there is any alteration in the order the usage records are returned (for a specific subscription for a specific date).
I am sure that Microsoft stores this data in some database. I can’t find the unique id to identify a usage record from many records returned by the Billing API. Maybe I am missing something here.
I will appreciate any help or any pointers on this.
When you call the Usage API set the ShowDetails parameter to true:
&showDetails=true
MSDN Doc
This will populate the instance data in the returned JSON with the unique URI for the resource which includes the name for example:
Website:
Virtual Machine:
If ShowDetails is false all your resources will be aggregated on the server side based on the resource type, all your websites will show as one entry.
The resource URI, date range and meterid will form a unique key as far as I know.
NOTE: If you are using the legacy API your VMs will be aggregated under the cloud service hosting them.