0
votes

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?

1
But if it's a batch it will only be availalbe for a short time. Checkout github.com/spring-projects/spring-batch/blob/master/… - Simon Martinelli
What do you mean by short time?Also, as i refer online,some source said,i just need to add dependency on artifacts. micrometer-core and micrometer-registry-prometheus and nothing else,i assume it will automatically push to /actuator/promethous and then i can scraping can be done from there.Why do we need PrometheusConfiguration class? - user124
It's a batch application, isn't it? How do you start it? - Simon Martinelli
yes its a spring batch application.When i run main class, then all the jobs will be loaded and since all jobs are scheduled daily based on cron expression, so the main will be running forever continuous as there are always jobs to execute in future?Did i miss anything? - user124
Now I understand. If you only add Actuator there will be no Webserver. You have to add the web starter too - Simon Martinelli

1 Answers

0
votes

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.