Extract Azure billing information.
- You must be a billing admin.
- Login to azure before running the command
az login
- The command takes some time. You might want to filter the response in a number of different ways. Better to store the query results in a file, for example:
python fetch_usage_details.py <your sunscription id here> 2024-07-01 2024-07-31 > ~/Downloads/az_usage_details_2024-07-01_2024-07-31.json
Use jq command to perform all kind of querying on the data. Here are some examples.
Using price multiplied by quantity:
cat ~/Downloads/az_usage_details_2024-07-01_2024-07-31.json | jq '[.value[] | .properties | .effectivePrice * .quantity] | add'
Using the cost in billing currency. Both answers must match:
cat ~/Downloads/az_usage_details_2024-07-01_2024-07-31.json | jq '[.value[] | .properties.costInBillingCurrency] | add'
cat ~/Downloads/az_usage_details_2024-07-01_2024-07-31.json | jq '
.value |
group_by(.properties.instanceName | split("/") | last) |
map({
instance: .[0].properties.instanceName | split("/") | last,
totalCost: map(.properties.effectivePrice * .properties.quantity) | add
}) |
sort_by(-.totalCost) |
. as $instances |
{
instances: $instances,
grandTotal: ($instances | map(.totalCost) | add)
}'