1

Prometheus gathers metrics of a SpringBoot application every 15 seconds. We use micrometer for producing the metrics. If the application is shut down (pod restart etc.), we might loose metrics data of the last 15s. This might be bearable. Nevertheless I'm looking for a possibility to fix this.

Besides other approaches (pushing metrics, persisting them, etc.), I'm investigating whether it's possible to pause the application on shutdown such that it does not run any business code (which would result in increasing Prometheus counters) while still serving /actuator/prometheus.

I've tried using Thread.sleep in @PreDestroy and several similar approaches. But no matter which hook I use, It's too late for setting flags, etc. -- /actuator/prometheus is already shut down.

How can I pause the application while leaving /actuator/prometheus operable for 15s so it can be scraped? Is there a hook which gets triggered early enough so actuator is still working?

R2C2
  • 728
  • 6
  • 19
  • could Spring Boot graceful shutdown help with this? https://docs.spring.io/spring-boot/docs/current/reference/html/web.html#web.graceful-shutdown – Brian Clozel Jun 26 '23 at 12:25
  • Unfortunately graceful shutdown doesn't help here. Whether or not it is active: after receiving the shutdown signal, `/actuator/prometheus` cannot be queried anymore. – R2C2 Jun 26 '23 at 13:27

0 Answers0