Skip to content

Instantly share code, notes, and snippets.

@ivanthelad
Last active July 29, 2025 11:03
Show Gist options
  • Save ivanthelad/ade5ef2770d245a1013f7e0b51728461 to your computer and use it in GitHub Desktop.
Save ivanthelad/ade5ef2770d245a1013f7e0b51728461 to your computer and use it in GitHub Desktop.
# 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

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

"Volume in GB per Hour"

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"

Break down of total cost of the microservice

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"

Show cost over time per microservice

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)")

Perform a microservice cost project for next month or year

// 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)"

Breakdown per namespace

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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment