Search code examples
javaspringmicroservicesmicrometer

How to measure the total time of an asynchronous process using micrometer and prometheus (PromQL)?


I have the following microservices scenario

Microservice 1

1 - Collect a System.getCurrentTimeMillis

2 - Generate an id after an operation in the DB

3 - This step should send the ID and the initial time of the operation to Prometheus

Microservice 7

1 - Finish processing the message with the ID generated in the first microservice

2 - Collect a System.getCurrentTimeMillis

3 - This step should send the ID and the final time of the operation to Prometheus

How can I implement step 3 and then use PromQL to measure the total transaction time?

The data can be displayed in prometheus as a histogram as in the display of http requests if possible.


Solution

  • The method you've described isn't really how Prometheus is intended to be used. You are describing logging or tracing. (See Zipkin, Jaeger, etc)

    Metrics sent to Prometheus are in aggregate. So you won't (typically) be able to tease out individual calls. (Any hacks used to make it work won't scale very far)

    Micrometer/Prometheus would be best used to track the aggregate durations the individual steps of your processing are taking.