Forum Discussion
Ashok42470
May 13, 2025Copper Contributor
AKS Pod resource utilization (CPU/Memory) alert
Hi All, I am trying to set up an alert for AKS pod CPU/Memory utilization alert when a max utilization hits certain threshold (let's say >95%). Sample query for CPU utilization. let cpuusage = mate...
Kidd_Ip
May 14, 2025MVP
How about this:
let cpuusage = materialize(
Perf
| where ObjectName == 'K8SContainer'
| where CounterName has 'cpuUsageNanoCores'
| extend ContainerNameParts = split(InstanceName, '/')
| extend ContainerNamePartCount = array_length(ContainerNameParts)
| extend PodUIDIndex = ContainerNamePartCount - 2, ContainerNameIndex = ContainerNamePartCount - 1
| extend ContainerName = strcat(ContainerNameParts[PodUIDIndex], '/', ContainerNameParts[ContainerNameIndex])
| summarize AggregatedValue=max(CounterValue) by bin(TimeGenerated, 10m), ContainerName
| project TimeGenerated, ContainerName, AggregatedValue
);
let cpulimits = materialize(
Perf
| where ObjectName == 'K8SContainer'
| where CounterName == 'cpuLimitNanoCores'
| extend ContainerNameParts = split(InstanceName, '/')
| extend ContainerNamePartCount = array_length(ContainerNameParts)
| extend PodUIDIndex = ContainerNamePartCount - 2, ContainerNameIndex = ContainerNamePartCount - 1
| extend ContainerName = strcat(ContainerNameParts[PodUIDIndex], '/', ContainerNameParts[ContainerNameIndex])
| extend CpuNanoCoreLimit= CounterValue
| project ContainerName, CpuNanoCoreLimit
);
let cpu_threshold_exceeded = cpuusage
| join kind=inner cpulimits on ContainerName
| extend CPU_mCores_Usage = AggregatedValue / 1000000
| extend CPU_mCores_Limit = CpuNanoCoreLimit / 1000000
| extend Cpu_Perct_utilization = round((CPU_mCores_Usage / CPU_mCores_Limit) * 100, 2)
| where Cpu_Perct_utilization > 95
| summarize count() by ContainerName, bin(TimeGenerated, 30m)
| where count_ >= 3
| project ContainerName, TimeGenerated, count_;
cpu_threshold_exceeded