Saturday 22 April 2023

Restart Count Details of Each Pod and Container for App in Grafana Chart with Azure Monitor for AKS

 Pod and container restart counts monitoring are discussed in posts "Pod Restart Counts Grafana Chart with Azure Monitor for AKS" and "Container Restart Counts Grafana Chart with Azure Monitor for AKS". Those two charts show summarized view per service. To view details of pod and container restarts for an individual service we can create another chart as described in this post.

Expected Outcome

Panel showing each individual pod restarts and container restarts count details over time.

We can use the query below to create the pod and container restart count details panel in Grafana with Azure monitor. The variable aksservice used here to allow the user to sect the required deployment in the Grafana board so the panel can be used to see the required service container and pod restarts.

//| where $__timeFilter(TimeGenerated) // use only in grafana
| where ClusterName == "aks-chdemo-dev04"
| where Namespace in('mydemo')
| extend pod_label = todynamic(PodLabel)
| extend app_name = todynamic(pod_label[0].app)
| where app_name == "${aksservice:text}"
| summarize container_restarts = sum(ContainerRestartCount), pod_restarts = sum(PodRestartCount) by TimeGenerated, tostring(app_name), Name
| where container_restarts > 0 or pod_restarts > 0
| order by TimeGenerated asc
| project TimeGenerated,app_name, Name, container_restarts, pod_restarts

The full json for Grafana panel is available in GitHub here. You can replace the id of the panel and the subscription, log analytics workspace name, resource group name etc.

No comments:

Popular Posts