Answers: <p>I had similar problem. I found no straightforward solution, bur eventually I solved it with a workaround.</p>
  <p>The problem is that <code>kube_job_status_succeeded</code> will always present number of rows equal to <code>.spec.successfulJobsHistoryLimit</code> (if some jobs in the past have succeded) with value of 1, and number of rows equal to <code>.spec.failedJobsHistoryLimit</code> (if some jobs in the past have failed) with value of 0. Moreover, <code>kube_job_status_succeeded</code> does not tell you when the job was performed.</p>
  <p>In other words, <code>kube_job_status_succeeded</code> just store <code>.spec.successfulJobsHistoryLimit</code> (default: 3) of most recent succesful jobs and <code>.spec.failedJobsHistoryLimit</code> (default: 1) of most recent failed jobs</p>
  <p>My workaround is based on joining data from kube_job_status_succeeded and kube_job_created. In this way, I take most recent timestamp of successful job. Then  I deduct it from current timestamp. In result I get a info how long ago last successful job execution took a place.</p>
  <pre><code>time() - max(kube_job_status_succeeded{namespace=&quot;my_namespace&quot;,job_name=~&quot;job_name.*&quot;} * on (job_name) kube_job_created{namespace=&quot;my_namespace&quot;,job_name=~&quot;job_name.*&quot;})
  </code></pre>
  <p>In Grafana it looks like this:</p>
  <p><a href="https://i.sstatic.net/Fp1OT.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Fp1OT.png" alt="enter image description here" /></a></p>
  <p>Maybe this is not direct answer to your question, but I believe that this might be a good starting point to achieve your goal. In Grafana you can do some data mapping to present time diff calculated in the query as one big &quot;success&quot;/&quot;failed&quot; label, depending on your neads</p>
  
Answers: CC BY-SA 4.0
Answers: 2021-11-29T14:26:58.633Z
Answers: 2021-11-29T14:26:58.633Z
Answers: Irek L.
Answers: <p>Did you try to set the <code>.spec.successfulJobsHistoryLimit</code> to 1 instead of the default value of 3?</p>
  <p><a href="https://kubernetes.io/docs/tasks/job/automated-tasks-with-cron-jobs/#jobs-history-limits" rel="nofollow noreferrer">https://kubernetes.io/docs/tasks/job/automated-tasks-with-cron-jobs/#jobs-history-limits</a></p>
  
Answers: CC BY-SA 4.0
Answers: 2021-09-26T18:26:41.670Z
Answers: 2021-09-26T18:26:41.670Z
Answers: 030
Body: <p>I'm trying to create a Dashboard in Grafana that will show the status of Cronjob &amp; Job success &amp; fail.</p>
  <p>Currently i'm using <code>kube_job_status_succeeded</code> to get a status job, but the issue here PromQL also take a 3 days of job status back, but i only wanted for 1 days job status.</p>
  <p>I try to be creative with <code>kube_job_created</code> but no luck.</p>
  <p>How can i get only <code>kube_job_status_succeeded</code> for 1 day only ? Thank you.</p>
  
Tags: <kubernetes><monitoring><prometheus><grafana>
Title: Monitoring Kubernetes CronJob & Job in Grafana for today day only
UserDisplayName: DagaReiN
ThreadText: # Monitoring Kubernetes CronJob & Job in Grafana for today day only
  
  (Asked by: username_0 on 2021-09-26)
  
  I'm trying to create a Dashboard in Grafana that will show the status of Cronjob & Job success & fail.
  
  Currently i'm using `kube_job_status_succeeded` to get a status job, but the issue here PromQL also take a 3 days of job status back, but i only wanted for 1 days job status.
  
  I try to be creative with `kube_job_created` but no luck.
  
  How can i get only `kube_job_status_succeeded` for 1 day only ? Thank you.
  
  **Tags:** kubernetes, monitoring, prometheus, grafana
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2021-11-29. Score: 1
  
  I had similar problem. I found no straightforward solution, bur eventually I solved it with a workaround.
  
  The problem is that `kube_job_status_succeeded` will always present number of rows equal to `.spec.successfulJobsHistoryLimit` (if some jobs in the past have succeded) with value of 1, and number of rows equal to `.spec.failedJobsHistoryLimit` (if some jobs in the past have failed) with value of 0. Moreover, `kube_job_status_succeeded` does not tell you when the job was performed.
  
  In other words, `kube_job_status_succeeded` just store `.spec.successfulJobsHistoryLimit` (default: 3) of most recent succesful jobs and `.spec.failedJobsHistoryLimit` (default: 1) of most recent failed jobs
  
  My workaround is based on joining data from kube\_job\_status\_succeeded and kube\_job\_created. In this way, I take most recent timestamp of successful job. Then I deduct it from current timestamp. In result I get a info how long ago last successful job execution took a place.
  
  ```
  time() - max(kube_job_status_succeeded{namespace="my_namespace",job_name=~"job_name.*"} * on (job_name) kube_job_created{namespace="my_namespace",job_name=~"job_name.*"})
  
  ```
  
  In Grafana it looks like this:
  
  [![enter image description here](https://i.sstatic.net/Fp1OT.png)](https://i.sstatic.net/Fp1OT.png)
  
  Maybe this is not direct answer to your question, but I believe that this might be a good starting point to achieve your goal. In Grafana you can do some data mapping to present time diff calculated in the query as one big "success"/"failed" label, depending on your neads
  
  
  ---
  
  ### Answer by username_2 on 2021-09-26. Score: 0
  
  Did you try to set the `.spec.successfulJobsHistoryLimit` to 1 instead of the default value of 3?
  
  <https://kubernetes.io/docs/tasks/job/automated-tasks-with-cron-jobs/#jobs-history-limits>
  
  
  ---
  
  