---
title: Summarize container restarts
description: Calculate p50, p90, and max Kubernetes container restarts per deployment using `groupby` with `percentile` and `max`.
url: https://coralogix.com/docs/dataprime/cookbook/counting_container_restarts/
product: dataengine
feature: DataPrime Language
feature_id: dataprime-language
feature_identifier: dataengine/dataprime-language
last_updated: '2026-11-02'
---

# 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:

| 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             |
