- 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.
- 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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…