Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Know Your Cloud Resource Costs on Azure
public async Task<IEnumerable<ResourceGroupCost>> GetResourceGroupCostsAsync(
Subscription subscription,
DateTime dateStart,
DateTime dateEnd,
string authToken)
var costs = await GetResourceCostsAsync(subscription.SubscriptionId, dateStart, dateEnd, authToken).ConfigureAwait(false);
var grouped = costs.GroupBy(
p => new
DateStart = p.UsageValue.Properties.UsageStartTime,
DateEnd = p.UsageValue.Properties.UsageEndTime,
ResourceGroupName = ResourceGroupDateKey.GetResourceGroupKey(p)
p => new ResourceGroupCost()
ResourceGroupName = p.Key.ResourceGroupName,
DateStart = DateTimeOffset.Parse(p.Key.DateStart),
DateEnd = DateTimeOffset.Parse(p.Key.DateEnd),
Cost = p.Sum(q => q.CalculatedCosts)
.OrderBy(p => p.ResourceGroupName)
.ThenBy(p => p.DateStart)
.ThenBy(p => p.DateEnd);
return grouped;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment