Skip to content

Summarize Container Restarts by Deployment

Problem / use case

You want to track Kubernetes container stability by calculating restart counts per deployment. This helps spot unhealthy pods or unstable deployments using percentiles and max values.

Query

source logs
| choose resource.attributes.k8s_container_restart_count as restarts, 
    resource.attributes.k8s_deployment_name as deployment
| filter restarts > 0
| groupby deployment agg
    round(percentile(0.5, restarts), 2) as p50_restarts,
    round(percentile(0.9, restarts), 2) as p90_restarts,
    round(max(restarts), 0) as max_restarts
| orderby max_restarts desc

Note

remember that certain fields like resource.attributes.k8s_container_restart_count may require to be casted into a number type

Expected output

A sorted table showing deployments with the highest container restart counts:
deploymentp50_restartsp90_restartsmax_restarts
cartservice231.9233235
recommendationservice3232.5233
loadgenerator242425
k8s-watcher455
otelcollector444
emailservice444