Copy as Markdown[Open in ChatGPT](https://chatgpt.com/?q=Read%20https%3A%2F%2Fcoralogix.com%2Fdocs%2Fdataprime%2Fcookbook%2Fcounting_container_restarts.md%20and%20help%20me%20with%20my%20question%20about%20this%20Coralogix%20documentation%20page.)[Open in Claude](https://claude.ai/new?q=Read%20https%3A%2F%2Fcoralogix.com%2Fdocs%2Fdataprime%2Fcookbook%2Fcounting_container_restarts.md%20and%20help%20me%20with%20my%20question%20about%20this%20Coralogix%20documentation%20page.)

# Summarize container restarts by deployment

## Problem / Use case[​](#problem--use-case "Direct link to 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[​](#query "Direct link to 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[​](#expected-output "Direct link to Expected output")

A sorted table showing deployments with the highest container restart counts:

| deployment            | p50\_restarts | p90\_restarts | max\_restarts |
| --------------------- | ------------- | ------------- | ------------- |
| cartservice           | 231.9         | 233           | 235           |
| recommendationservice | 32            | 32.52         | 33            |
| loadgenerator         | 24            | 24            | 25            |
| k8s-watcher           | 4             | 5             | 5             |
| otelcollector         | 4             | 4             | 4             |
| emailservice          | 4             | 4             | 4             |
