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?