2

From what I read, I understood that I can go with Histogram metric type if I want to measure the time taken of a single request. But If I want to measure the time taken between two different requests, which approach I can go with?

for example, let's say, in one of the API requests, there is an event that occurs (let's call it A) for an entity (let's call it Order) and in one of the other request, there is another event that occurs (let's call it B) for the same order.

Now, I would like to measure the time duration between events A and B for all the orders.

I would like to understand how I can achieve this using Prometheus.

Manoj Kumar S
  • 634
  • 8
  • 16
  • If you don't need to know exactly which order it was and if you can save somewhere (in a database for example) the time when A happened, then whenever B happens you can calculate how much time has passed since A and export the value as a metric. – anemyte Oct 29 '21 at 10:17
  • Yes, that's a possible solution, but I don't want to persist this data. I believe I can log metrics whenever A and B happen. So I would like to understand if there are ways in Prometheus to measure time duration using these metrics. – Manoj Kumar S Nov 01 '21 at 05:37
  • 1
    There is a way but it does not scale well. Export timestamps of both events in unixtime, then subtract one from the other. The problem of this method comes from _"all the orders"_, you will have to place an unbound label to distinguish one order from another. Metrics with extreme label cardinality can make Prometheus run out of RAM. – anemyte Nov 01 '21 at 07:20

0 Answers0