Last active
July 12, 2021 04:56
-
-
Save kshitijcode/e222c7a2658782b6c6535ed0713f4cc9 to your computer and use it in GitHub Desktop.
Kusto Query for Plotting Pod CPU consumption in Grafana for Azure Kubernetes Service and Log Analytics
This file contains 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
KubePodInventory | |
| where ClusterName == 'prod-aks-cluster' | |
| where isnotempty(Computer) // eliminate unscheduled pods | |
| where PodStatus in ('Running') | |
| extend podLabels = parse_json (PodLabel) | |
| where podLabels[0]['app.kubernetes.io/instance'] == "payments-service" | |
| where Namespace == "payment-ns" | |
| where $__timeFilter(TimeGenerated) | |
| extend ActualContainerName=tostring(split(ContainerName, '/')[1]) | |
| extend InstanceName=strcat(ClusterId, '/', PodUid, '/', ActualContainerName) | |
| summarize by bin(TimeGenerated, 1m),InstanceName, Name | |
| join ( | |
Perf | |
| where ObjectName == 'K8SContainer' | |
| where CounterName == 'cpuUsageNanoCores' | |
| where $__timeFilter(TimeGenerated) | |
| summarize UsageValue = avg(CounterValue) by bin(TimeGenerated, 5m),InstanceName, CounterName | |
| project-away CounterName | |
) on InstanceName,TimeGenerated | |
| summarize TotalCpuConsumedCores = avg(UsageValue/1000000) by bin(TimeGenerated,5m), Name | |
| order by TimeGenerated asc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment