Use prometheus query result from a different query in Grafana

Viewed 1490

How do I use prometheus query result from a different query in the same panel in Grafana.

Example,

I have 3 Prometheus queries in Grafana,

  1. sum(increase(metric1[1h])) say, #A
  2. sum(increase(metric2[1h])) say, #B

Now, in the 3rd query I want to calculate the percent difference using the two results, similar to what we were able to do using Graphite metrics.

(#B - #A)/#A

How can I achieve this since Grafana does not seem to recognise these identifiers in Prometheus queries.

enter image description here

1 Answers

Do the following:

  1. Click on the "Transform" tab

  2. Click on the "Add transformation" button

  3. Choose the "Add field from calculation" option

  4. Select "Mode" = "Binary operation" and the desired operation

Note: you can use two transformations to get "(B - A) / A".

See the following example:

enter image description here

Related