简体   繁体   English

使用千分尺发布 Spring 批量指标

[英]Publishing Spring Batch metrics using Micrometer

I have an app that contains 2 dozen of spring batch cron jobs.There is no rest controller as it is an analytics app and it runs daily and read data from db, process it, and then store aggregated data in another db.I want to have spring inbuilt metrics on the jobs using micrometer and push them to Prometheus.As my app is not a webserver app, so still micrometer will be publishing results on HOST:8080? I have an app that contains 2 dozen of spring batch cron jobs.There is no rest controller as it is an analytics app and it runs daily and read data from db, process it, and then store aggregated data in another db.I want to在使用千分尺的作业上有 spring 内置指标并将它们推送到 Prometheus。由于我的应用程序不是网络服务器应用程序,所以千分尺仍然会在 HOST:8080 上发布结果吗? Will actuator automatically start a new server on HOST:8080?or do we need to have application server running on 8080?执行器会自动在 HOST:8080 上启动新服务器吗?还是我们需要在 8080 上运行应用程序服务器?

My understanding is that actuator and application server can run of different ports as these are different processes?Even if application server is there or not, actuator should be able to either use same port as application server port, or it can use different port?我的理解是执行器和应用程序服务器可以运行不同的端口,因为它们是不同的进程?即使应用程序服务器存在与否,执行器应该能够使用与应用程序服务器端口相同的端口,还是可以使用不同的端口?

So if my application is not a webserver based app, still I can access metrics at localhost:8080/actuator/ and publish to Prometheus?因此,如果我的应用程序不是基于网络服务器的应用程序,我仍然可以在 localhost:8080/actuator/ 访问指标并发布到 Prometheus?

Prometheus is a pull-based system, meaning you give it a URL from your running application and it will go pull metrics from it. Prometheus 是一个基于拉取的系统,这意味着你从正在运行的应用程序中给它一个 URL,它会 go 从中拉取指标。 If your application is an ephemeral batch application, it does not make sense to make it a webapp for the only sake of exposing a URL for a short period of time.如果您的应用程序是临时批处理应用程序,那么仅仅为了在短时间内公开 URL 而将其设为 webapp 是没有意义的。 That's exactly why Prometheus folks created the Push gateway, see When to use the Push Gateway .这正是 Prometheus 人员创建推送网关的原因,请参阅何时使用推送网关

Now with is in mind, in order for your batch applications to send metrics to Prometheus, you need:现在请记住,为了让您的批处理应用程序将指标发送到 Prometheus,您需要:

  • A Prometheus server普罗米修斯服务器
  • A Pushgateway server Pushgateway 服务器
  • An optional metrics dashbaord (Grafana or similar, Prometheus also provides a built-in UI)一个可选的指标仪表板(Grafana 或类似的,Prometheus 也提供了一个内置的 UI)
  • Make your batch applications push metrics to the gateway让您的批处理应用程序将指标推送到网关

A complete example with this setup can be found in the Batch metrics with Micrometer .可以在使用 Micrometer 的批处理指标中找到有关此设置的完整示例。 This example is actually similar to your use case.此示例实际上与您的用例相似。 It shows two jobs scheduled to run every few seconds which store metrics in Micrometer's main registry and a background task that pushes metrics regularly from Micrometer's registry to Prometheus's gateway.它显示了两个计划每隔几秒运行一次的作业,它们将指标存储在 Micrometer 的主注册表中,以及一个后台任务,该任务定期将指标从 Micrometer 的注册表推送到 Prometheus 的网关。

Another option is to use the RSocket protocol, which is provided for free if you use Spring Cloud Dataflow .另一种选择是使用 RSocket 协议,如果您使用Spring Cloud Dataflow ,该协议是免费提供的。

For Spring Boot, there are no actuator endpoints for Spring Batch, please refer to Actuator endpoint for Spring Batch for more details about the reasons about this decision.对于 Spring Boot,没有 Spring Batch 的执行器端点,请参阅 Spring Batch 的执行器端点以了解有关此决定的原因的更多详细信息。

@Mahmoud I think there are valid use cases for exposing the health endpoints optionally. @Mahmoud 我认为有一些有效的用例可以选择性地公开健康端点。 The first question to consider is when we say a batch operation runs for a short time, how short is that time - a few minutes?要考虑的第一个问题是,当我们说批处理操作运行时间很短时,该时间有多短——几分钟? I agree there's no need;我同意没有必要; but how about jobs that run for a few hours?但是运行几个小时的作业呢? it's important for some jobs that we get metrics especially when such jobs are bound by a business SLA and the operator needs to know if the job is processing at the required operations per second, has the right connection pool size etc.对于某些作业,我们获得指标很重要,尤其是当此类作业受业务 SLA 约束并且操作员需要知道作业是否以每秒所需的操作进行处理时,是否具有正确的连接池大小等。

There are also a variety of implementation details of the running platform - we can use Spring Batch without SCDF, not be in control of the Prometheus gateway to be able to use push, run in a cloud where Istio will pull the metrics automatically etc.还有各种运行平台的实现细节——我们可以使用没有 SCDF 的 Spring Batch,不受 Prometheus 网关控制以能够使用推送,在 Istio 将自动拉取指标的云中运行等。

For the OPs question, in general one can run a spring batch job in web instance and use the shutdown endpoint after the job completion notification.对于 OPs 问题,通常可以在 web 实例中运行 spring 批处理作业,并在作业完成通知后使用关闭端点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 Spring 微米中为端点启用指标 - Enable metrics for endpoints in Spring micrometer Spring 启动 2.x 批处理应用程序,如何访问千分尺缓存指标以进行日志记录? - Spring Boot 2.x Batch application, how to access Micrometer cache metrics for logging? 使用 spring java 的千分尺指标(没有 spring boot) - Micrometer metrics with spring java (NO spring boot) jersey 应用程序中的千分尺 Prometheus 指标(非弹簧) - Micrometer Prometheus metrics in jersey application (Non spring) 如何在不使用 Spring 或 Spring Boot 的情况下使用 Micrometer 在 TICK 堆栈上收集指标? - How to use Micrometer for metrics collection on TICK stack without using Spring or Spring Boot? Prometheus端点中不提供使用Micrometer的自定义指标 - Custom metrics using Micrometer is not available in Prometheus endpoint 如何从 spring-boot 千分尺检索指标 - How to retrieve metrics from spring-boot micrometer 从 jar 获取千分尺指标到 spring 引导应用程序 - Getting micrometer metrics from a jar to a spring boot application 在 Java springboot 应用程序中使用千分尺收集 HikariCp 指标,方法是在 - HikariCp metrics collection using micrometer in Java springboot application by configuring it in 使用 Micrometer 将 New Relic 与 Spring Boot 集成 - Integrate New Relic with Spring Boot using Micrometer
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM