Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
387 views
in Technique[技术] by (71.8m points)

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.?
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
  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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...