Give me a PromQL expression to see kubernetes jobs running since 1hour
- User
Give me a PromQL expression to see kubernetes jobs running since 1hour
- Assistant
Here is an example PromQL expression that shows the number of Kubernetes jobs running for at least one hour:
codecount(kube_job_status_active{job_name!="",status="active"}) by (job_name)This expression uses the
kube_job_status_activemetric, which shows the status of all active Kubernetes jobs, and filters for jobs with a non-emptyjob_nameandstatusof "active". Thecountaggregation function is then applied to the resulting set of jobs, grouped byjob_name, to show the number of active jobs for each job.Note that this expression only shows the number of active jobs, not their runtime. To see the runtime of each job, you can use the
kube_job_status_completion_timemetric, which shows the timestamp when each job completed. You can then use thetime()function to calculate the difference between the current time and the completion time, and filter for jobs that have been running for at least one hour using the>operator.Here is an example expression that shows the runtime of each active Kubernetes job that has been running for at least one hour:
codetime() - kube_job_status_completion_time{job_name!="",status="active"} by (job_name) > 3600Keep in mind that PromQL is a very powerful and expressive language, so there may be other ways to write expressions to achieve the same result. This is just one possible solution.