# Alerting on Long running pods

**URL:** <https://community.dynatrace.com/t/alerting-on-long-running-pods/49364>\
**Category:** Container platforms\
**Tags:** kubernetes, docker\
**Created:** [December 15, 2024, 6:55pm UTC](https://community.dynatrace.com/t/alerting-on-long-running-pods/49364 "2024-12-15T18:55:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![PujithAnne](https://avatars.discourse-cdn.com/v4/letter/p/eada6e/32.png) [@PujithAnne](https://community.dynatrace.com/u/PujithAnne)\
**Post date:** [December 15, 2024, 6:55pm UTC](https://community.dynatrace.com/t/alerting-on-long-running-pods/49364/1 "2024-12-15T18:55:57Z")

</div>

Hi Team,

Is there any alerting option to alert for long&nbsp;running pod in Kubernetes?

---

<div class="post-metadata">

**Author:** ![Maheedhar\_T](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/maheedhar_t/32/155_2.png) [@Maheedhar\_T](https://community.dynatrace.com/u/Maheedhar_T)\
**Post date:** [December 15, 2024, 8:36pm UTC](https://community.dynatrace.com/t/alerting-on-long-running-pods/49364/2 "2024-12-15T20:36:16Z")

</div>

Hi&nbsp;[@PujithAnne](https://community.dynatrace.com/user/64457)&nbsp;,  
Can you please explain further on what exactly you mean by alert for long running pods ?  
You want to be alerted if a pod runs more than x days?

---

<div class="post-metadata">

**Author:** ![PujithAnne](https://avatars.discourse-cdn.com/v4/letter/p/eada6e/32.png) [@PujithAnne](https://community.dynatrace.com/u/PujithAnne)\
**Post date:** [December 16, 2024, 2:09am UTC](https://community.dynatrace.com/t/alerting-on-long-running-pods/49364/3 "2024-12-16T02:09:35Z")

</div>

Yes, i want to get alert for pods under specific namespace over a 1 days.

---

<div class="post-metadata">

**Author:** ![gopher](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/gopher/32/5728_2.png) [@gopher](https://community.dynatrace.com/u/gopher)\
**Post date:** [December 16, 2024, 4:35am UTC](https://community.dynatrace.com/t/alerting-on-long-running-pods/49364/4 "2024-12-16T04:35:36Z")

</div>

[@PujithAnne](https://community.dynatrace.com/user/64457)&nbsp;can you please describe the alert scenario in a bit of detail so we can advise.  
Is there a specific scenario that you are trying to capture (not just that it’s running longer than xx).

I’m assuming that you are looking for an alert where a pod or a job has not terminated and is left&nbsp; in a ‘terminating’ status? these are covered by default

Or is this really a pod has not received a termination&nbsp; &nbsp;signal and is left running.&nbsp; - this would not be covered and you’d need some custom metrics and alerts to capture this.

---

<div class="post-metadata">

**Author:** ![PujithAnne](https://avatars.discourse-cdn.com/v4/letter/p/eada6e/32.png) [@PujithAnne](https://community.dynatrace.com/u/PujithAnne)\
**Post date:** [December 16, 2024, 5:31am UTC](https://community.dynatrace.com/t/alerting-on-long-running-pods/49364/5 "2024-12-16T05:31:51Z")

</div>

We have pods running a job that needs to be completed and needs to get terminated in 2-3hrs. We are seeing pods that are running for over than 12 hours consuming resources on kubernetes cluster. I have delete the pods if it’s older than 1 days to reduce the resource consumption.

Thanks,

Pujith

---

<div class="post-metadata">

**Author:** ![gopher](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/gopher/32/5728_2.png) [@gopher](https://community.dynatrace.com/u/gopher)\
**Post date:** [December 16, 2024, 5:50am UTC](https://community.dynatrace.com/t/alerting-on-long-running-pods/49364/6 "2024-12-16T05:50:17Z")

</div>

[@PujithAnne](https://community.dynatrace.com/user/64457)&nbsp;,

out of the box, you’re probably up the creek without a paddle.&nbsp; uptime isn’t kept as a searchable counter (as far as I know).&nbsp; there is an uptime counter in Prometheus for kube pod metrics you could look at, but not sure if there would be suitable logic in grail to work out if it’s above a set value (pre-calculated).

alternatively - you can use Kubernetes native methods like activeDeadlineSeconds to specify the maximum running time of a pod in your deployment spec.  
&nbsp;\*\*\*use with extreme caution\*\*\* if time is up, it will terminate the pod. but you’ll get what you’re after and pod won’t run for longer than expected.&nbsp; you could theoretically set it for say ‘6 hours’ or something at a point where you would consider it a lost cause and effectively safe to terminate.

```auto
apiVersion: v1
kind: Pod
metadata:
  name: example-pod
spec:
  activeDeadlineSeconds: 3600 # Pod will be terminated after 1 hour (3600 seconds)

```

Good luck
