prometheus promql to fetch pods within certain time

646 views Asked by At

Team, i have a query to pull certain expression matched pods and namespaces but i want to pull them for last x number of days. how to ?

count(kube_pod_info{namespace=~"team-.*", pod=~"export-.*"} ) by (namespace)

output

Element--------------------------------------------- Value

{namespace="team-a4-db8a1b8b054f"}  500

attempted query to get same result for last 1d: see in end of query [1d]

count(kube_pod_info{namespace=~"team-.*", pod=~"export-.*"} ) by (namespace)[1d]

error output

Error executing query: invalid parameter 'query': 1:195: parse error: ranges only allowed for vector selectors
1

There are 1 answers

0
trallnag On

Try this:

count by (namespace) (
  max_over_time(kube_pod_info{namespace=~"team-.*", pod=~"export-.*"}[1d])
)