Skip to content
Advertisement

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? 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?

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

Advertisement

Answer

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.

Now with is in mind, in order for your batch applications to send metrics to Prometheus, you need:

  • A Prometheus server
  • A Pushgateway server
  • An optional metrics dashbaord (Grafana or similar, Prometheus also provides a built-in 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. 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.

Another option is to use the RSocket protocol, which is provided for free if you use 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.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement