I would like to use Micrometer to collect duration metrics for a task that starts in one Java process and finishes in another Java process (communicating via Kafka between them).
I was thinking to use LongTaskTimer.start()
that returns a LongTaskTimer.Sample
object, then pass it to the second process along with the Kafka message, and then use LongTaskTimer.Sample.stop()
to record the task duration. But it is not clear whether LongTaskTimer.Sample
objects can be serialized, and also in general whether such approach could work.
Is it possible to make the above approach work? How? If not, what is the easiest way to achieve the stated goal?
Not sure if it matters - my runtime environment is Spring Boot 2, and I am collecting the metrics to Prometheus (using standard micrometer prometheus registry).
Micrometer doesn't support metrics that spawn across multiple JVMs. Your options are:
Use multiple metrics and then create a view in grafana that will have a query that sums two (or more) metrics. It won't probably be an exact measurement of the flow, but rather some kind of average value that can provide a "feeling" of what happens in the system.
Use some kind of tracing software. Stuff like Jaeger (see here an example)