How can I programmatically retrieve the cost of a completed Azure Batch job? I'm interested in how much the job cost to run based on total run time within a given pool. Thanks.
How can I programmatically retrieve the cost of a completed Azure Batch job? I'm interested in how much the job cost to run based on total run time within a given pool. Thanks.
I ended up querying the cost management API using a resource ID filter to retrieve the information I need. This works for us because we use auto pool specifications for our batch jobs and we name the pools using a convention (so we know the pool ID based on the job ID). Here's what I'm doing if anybody needs to do the same.
{
"type": "ActualCost",
"dataSet": {
"granularity": "None",
"aggregation": {
"totalCost": {
"name": "Cost",
"function": "Sum"
}
},
"grouping": [
{
"type": "Dimension",
"name": "ResourceId"
}
],
"filter": {
"Dimensions": {
"Name": "ResourceId",
"Operator": "In",
"Values": [
"/subscriptions/{subscription_id}/resourcegroups/{resource_group}/providers/microsoft.batch/batchaccounts/{batch_account}/pools/{pool_id}"
]
}
}
}
}
Hello @TysonJones-1548 ,
Thanks for your query ! Not sure what is the reason for programmatic approach for retrieving the cost , because Azure Portal it self provides couple of resources through which we can find the cost of the batch job in a given pool.
Basically cost of Batch Job depends on multiple parameters like VM Size , Storage Transactions , etc. and that cost can be optimized by running Low-Priority VMs.
Reference :-
You can try using the API Get-AzureRmConsumptionUsageDetail by passing the reference
Example: Get-AzureRmConsumptionUsageDetail -BillingPeriodName 201710 -InstanceName <nameofinstance> -Top 10
Couple of REST APIs:
https://docs.microsoft.com/en-us/rest/api/batchservice/job/get
https://docs.microsoft.com/en-us/azure/batch/batch-apis-tools
Regards,
Shiva.
Hi Shiva, thanks for your reply. We have our own custom software where users can run jobs and we're using Azure Batch as the engine for this. One of our requirements is to report how much each job cost us to run. I'm not too concerned with data transfer costs but we would definitely like to know how much it cost to run the VM/s for the duration of the job.
9 people are following this question.