2

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.

2 Answers 2

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

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.