Quick set of scripts to break down the cost of microservices logs runing on AKS. uses the gb storage cost to calculate the storage cost over time
Take care. The container-name is used. So if you have deployments that use the same container name in multiple deployments, you will need to split the data based on namespace or resource
let daystosearch = 24h;
ContainerLogV2
| where _IsBillable == true
| where TimeGenerated > startofday(ago(daystosearch))
| project _BilledSize, PodName, TimeGenerated, myapp = strcat(PodNamespace, ":",ContainerName)
| summarize VolumeInGB = round(sum(_BilledSize) / (1024 * 1024 * 1024), 4), TotalMBytes = round(sum(_BilledSize) / (1024 * 1024), 2) by bin(TimeGenerated, 1h), myapp
| order by VolumeInGB
| render timechart title = "Volume in GB per Hour"
let pricingPerGigAnalytic = 2.99;
let pricingPerGigBasic = 0.645;
ContainerLogV2
| where _IsBillable == true
| where TimeGenerated > startofday(ago(31d))
| extend Application = ContainerName
| project _BilledSize, Application, TimeGenerated, PodNamespace
| summarize
RecordCount = count(),
TotalBilledBytes = sum(_BilledSize),
TotalGB = round(sum(_BilledSize) / 1024.0 / 1024.0 / 1024.0, 2),
TotalMBytes = round(sum(_BilledSize) / 1024.0 / 1024.0, 2),
CurrentCostEuro = round(pricingPerGigAnalytic * sum(_BilledSize) / 1024.0 / 1024.0 / 1024.0, 2),
CurrentCostEuroBasic = round(pricingPerGigBasic * sum(_BilledSize) / 1024.0 / 1024.0 / 1024.0, 2)
by Application, PodNamespace
| order by CurrentCostEuro desc, RecordCount desc, Application
| render table title="Cost estimate per Controller"
let pricingPerGigAnalytic = 2.99;
let pricingPerGigBasic = 0.645;
ContainerLogV2
| where _IsBillable == true
| where TimeGenerated > startofday(ago(31d))
| extend Application = ContainerName
| project _BilledSize, Application, TimeGenerated
| summarize
CurrentCostEuro = round(pricingPerGigAnalytic * sum(_BilledSize) / 1024.0 / 1024.0 / 1024.0, 2),
CurrentCostEuroBasic = round(pricingPerGigBasic * sum(_BilledSize) / 1024.0 / 1024.0 / 1024.0, 2),
TotalGB = round(sum(_BilledSize) / 1024.0 / 1024.0 / 1024.0, 2),
RecordCount = count()
by bin(TimeGenerated, 1h), Application
| project TimeGenerated,Application, Cost = CurrentCostEuro
| order by TimeGenerated asc, Cost
| render timechart with (ysplit=panels, title="Cost estimate per Controller over Time (1-hour windows)")
// Monthly cost projection based on daily usage
let pricingPerGigAnalytic = 2.99;
ContainerLogV2
| where _IsBillable == true
| where TimeGenerated > startofday(ago(7d))
| summarize DailyCost = round(pricingPerGigAnalytic * sum(_BilledSize) / 1024.0 / 1024.0 / 1024.0, 2)
by bin(TimeGenerated, 1d), ContainerName
| summarize AvgDailyCost = round(avg(DailyCost), 2) by ContainerName
| extend MonthlyProjection = round(AvgDailyCost * 30, 2)
| extend AnnualProjection = round(AvgDailyCost * 365, 2)
| project ContainerName, AvgDailyCost, MonthlyProjection, AnnualProjection
| order by MonthlyProjection desc
| render table title="Cost Projections by Container (Daily Average)"
let daystosearch = 2d;
ContainerLogV2
| where _IsBillable == true
| where TimeGenerated > startofday(ago(daystosearch))
| project _BilledSize, PodName, TimeGenerated, ContainerName, PodNamespace
//| where PodNamespace != "pets"
| summarize TotalMBytes = round(sum(_BilledSize) / (1024 * 1024), 2)by PodNamespace
| render piechart title = "Volume in last 2 days"