如何减去两个Prometheus指标以计算Pod执行的持续时间?

huangapple go评论56阅读模式
英文:

How to subtract two Prometheus metrics to calculate the duration of pod execution?

问题

I have this query gives me when pod terminated:

last_over_time(timestamp(kube_pod_status_phase{phase="Succeeded", pod=~"consumer-deployment.*"})[1h:])

and this gives me when pod is created:

last_over_time((kube_pod_created{pod=~"consumer-deployment.*"}[1h]))

but when I put - between them I get empty Empty query result.
What I can do?

英文:

Im trying to get the pods runnig time from the created moment to the termination
after tryin hunderd solution I think Im close
I have this query gives me when pod terminated

 last_over_time(timestamp(kube_pod_status_phase{phase="Succeeded",pod=~"consumer-deployment.*"})[1h:])  

and this gives me when pod is created

last_over_time((kube_pod_created{pod=~"consumer-deployment.*"}[1h]))

but when I put - between them I get empty Empty query result
What I can do ?

答案1

得分: 0

我认为我找到了一个解决方案,这个查询有效并返回了每个Pod的运行周期。

last_over_time(timestamp(kube_pod_status_phase{phase="Succeeded", pod=~"consumer-deployment.*"})[1h:])
  - ignoring(phase) group_right()
  last_over_time((kube_pod_created{pod=~"consumer-deployment.*"}[1h:]))
英文:

I think I found a solution this query worked and it return the runnig period for each pod

last_over_time(timestamp(kube_pod_status_phase{phase="Succeeded",pod=~"consumer-deployment.*"})[1h:])
  - ignoring(phase) group_right()
  last_over_time((kube_pod_created{pod=~"consumer-deployment.*"}[1h:]))

huangapple
  • 本文由 发表于 2023年6月26日 20:51:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/76556866.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定