We use Prometheus PushGateway for collecting metrics from short-lived cronjobs.
I would like to collect two metrics:
- How many times a particular cronjob finished without errors.
- How many times a particular cronjob failed with a fatal error.
Suppose I use Counter for this. From each particular cronjob point of view both metrics can be either 1 or empty (I'm incrementing either success or failure metric during a given cronjob executions). Also, I need to push those metrics with different groupingKey from each cronjob to avoid metric value overwrite (in case some job have parallel executions). I use timestamp as my groupingKey. Now, what I'm left with are the timeseries in the following format:
my_job_successful_executions{job="my-job", timestamp="2025-03-05:12:14:12"} = 1
my_job_successful_executions{job="my-job", timestamp="2025-03-05:12:29:12"} = 1
How can I get for example the following information: how many successful executions of cronjobs happened in the last hour vs. how many executions failed in the last hour?
To specify time window and use increase(), for example, I would need to have a range vector.
I can sum up all the values across all timeseries that I have:
sum(my_job_successful_executions{job="my-job"})
But that leaves me with another instant vector, I can't apply increase() to.
With Gauge I will be only having last state which won't allow me to query for the last hour / day etc.