使用 Micrometer 发布 Spring Batch 指标 [英] Publishing Spring Batch metrics using Micrometer

查看:137
本文介绍了使用 Micrometer 发布 Spring Batch 指标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含 2 打 Spring Batch cron 作业的应用程序.没有休息控制器,因为它是一个分析应用程序,它每天运行并从数据库读取数据,处理它,然后将聚合数据存储在另一个数据库中.我想使用 micrometer 在作业上设置 spring 内置指标并将它们推送到 Prometheus .由于我的应用程序不是网络服务器应用程序,所以 micrometer 仍然会在 HOST:8080 上发布结果?执行器会自动在 HOST:8080 上启动一个新的服务器吗?还是我们需要在 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 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? Will actuator automatically start a new server on HOST:8080?or do we need to have application server running on 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?

所以如果我的应用程序不是基于网络服务器的应用程序,我仍然可以在 localhost:8080/actuator/访问指标并发布到 Prometheus 吗?

So if my application is not a webserver based app, still I can access metrics at localhost:8080/actuator/ and publish to Prometheus?

推荐答案

Prometheus 是一个基于拉取的系统,这意味着您从正在运行的应用程序中给它一个 URL,它会从中提取指标.如果您的应用程序是一个临时的批处理应用程序,那么仅仅为了在短时间内公开 URL 就让它成为一个 web 应用程序是没有意义的.这正是 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. 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. 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 服务器
  • Pushgateway 服务器
  • 可选指标仪表板(Grafana 或类似工具,Prometheus 还提供内置 UI)
  • 让您的批处理应用程序将指标推送到网关

可以在 使用 Micrometer 批量度量.此示例实际上类似于您的用例.它显示了两个作业 计划每隔几秒运行一次,将指标存储在 Micrometer 的主注册表中,还有一个后台任务 推送指标定期从 Micrometer 的注册表到 Prometheus 的网关.

A complete example with this setup can be found in the Batch metrics with 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.

另一种选择是使用 RSocket 协议,如果您使用 Spring Cloud 数据流.

Another option is to use the RSocket protocol, which is provided for free if you use Spring Cloud Dataflow.

对于 Spring Boot,Spring Batch 没有执行器端点,请参考 Spring Batch 的执行器端点,了解有关此决定原因的更多详细信息.

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.

这篇关于使用 Micrometer 发布 Spring Batch 指标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆