Last active
July 28, 2022 02:03
-
-
Save binura-g/c34db3da557f492f8c4bd2dbeb467beb to your computer and use it in GitHub Desktop.
AKS Kusto - Pod CPU Usage percentage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let _Namespace = "namespace_name"; | |
let _ServiceName = "deployment_name"; | |
let _ContainerName = "container_name"; // required only if the Pod has multiple containers (eg. Sidecars) | |
let _BinSize = 1hr; // 5min, 0.5d, 2d, ... | |
let _ResourceLimitCounterName = 'cpuLimitNanoCores'; | |
let _ResourceUsageCounterName = 'cpuUsageNanoCores'; | |
KubePodInventory | |
| where Namespace == _Namespace | |
| where ServiceName == _ServiceName | |
| where ContainerName has _ContainerName | |
| extend InstanceName = strcat(ClusterId, '/', ContainerName), | |
ContainerName = strcat(ControllerName, '/', tostring(split(ContainerName, '/')[1])) | |
| distinct Computer, InstanceName | |
| join kind=inner hint.strategy=shuffle ( | |
Perf | |
| where ObjectName == 'K8SContainer' and CounterName == _ResourceLimitCounterName | |
| summarize MaxLimitValue = max(CounterValue) by Computer, InstanceName, bin(TimeGenerated, _BinSize) | |
| project | |
Computer, | |
InstanceName, | |
MaxLimitValue | |
) | |
on Computer, InstanceName | |
| join kind=inner hint.strategy=shuffle ( | |
Perf | |
| where ObjectName == 'K8SContainer' and CounterName == _ResourceUsageCounterName | |
| project Computer, InstanceName, UsageValue = CounterValue, TimeGenerated | |
) | |
on Computer, InstanceName | |
| project | |
Computer, | |
InstanceName, | |
TimeGenerated, | |
UsagePercent = UsageValue * 100.0 / MaxLimitValue | |
| summarize AvgCPUUsagePercentage = avg(UsagePercent) by bin(TimeGenerated, _BinSize), InstanceName | |
| render timechart; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment