问题描述
我有一个春季批处理作业,我想按照建议将指标推送到 Prometheus 这里
我需要通过测微计只推送 Spring 批处理给出的默认指标.有一种简单的方法,我不需要任何东西,只需添加以下依赖项:
<groupId>io.prometheus</groupId><artifactId>simpleclient_pushgateway</artifactId></依赖>
如前所述这里
但第二种方法是设置 PushGateway 服务器,然后编写 配置类
- 这两种方法有什么区别吗?
- 在第二种方法中,当我们只需要默认指标时如何编写它?Pushgatewayurl 很好,我理解,但是如果我有十几个作业,那么在作业名称和分组键中设置什么?
不,没有区别.请注意,并非所有 Spring Batch 用户都是 Spring Boot 用户.这就是 Spring Batch 存储库中的示例展示如何配置将指标推送到网关的任务的原因.现在,如果您使用 Spring Boot,则不必编写该类,因为 Spring Boot 会自动配置等效项.
- 在第二种方法中,当我们只需要默认指标时如何编写它?Pushgatewayurl 很好,我理解,但是如果我有十几个作业,那么在作业名称和分组键中设置什么.?
Spring Batch 指标由作业名称、步骤名称等标记,请参阅 表.因此,即使您有多个工作,指标也会有所不同.可以在 Prometheus 端使用相应的标签进行过滤.
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
- Is there any difference in these two approaches?
- 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.?
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.
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.
这篇关于如何将 Spring Batch Metrics 发布到 Prometheus Gateway的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!