springspring-batchprometheusmetricsprometheus-pushgateway

How to publish Spring Batch Metrics to Prometheus Gateway


I have a spring batch jobs in which I want to push metrics to Prometheus as suggested here

I have a requirement to push only default metrics given by Spring batch via micrometer.There is a easy way in which I dont have to anything and just add following dependency:

<dependency>
    <groupId>io.prometheus</groupId>
    <artifactId>simpleclient_pushgateway</artifactId>
</dependency>

as mentioned here

But the second way is setting up PushGateway server and then writing Configuration Class

  1. Is there any difference in these two approaches?
  2. In second approach how to write it when all we need is default metrics?Pushgatewayurl is fine ,I understood, but if I have dozen of jobs, what to set in jobname and grouping key.?

Solution

    1. Is there any difference in these two approaches?

    No, there is no difference. Please note that not all Spring Batch users are Spring Boot users. That's why the sample in Spring Batch's repository shows how to configure a task that pushes metrics to the gateway. Now if you use Spring Boot, you don't have to write that class since an equivalent is configured by Spring Boot automatically.

    1. In second approach how to write it when all we need is default metrics?Pushgatewayurl is fine ,I understood, but if I have dozen of jobs, what to set in jobname and grouping key.?

    Spring Batch metrics are tagged by job name, step name, etc, see the Tags column in the Built-in Metrics table. So even if you have multiple jobs, the metrics will be distinct. You can do the filtering on Prometheus side with the corresponding tag.