I have multiple metrics that are scraped using Prometheus and shown in Grafana. They all have the same labels.Ex:
metric1(currency=CURR1,application=APP1,env=ENV).
For certain currencies I have multiple metrics and for others I have only one. Ex:
metric1(currency=CURR1,application=APP1,env=ENV),
metric1(currency=CURR2,application=APP1,env=ENV),
metric1(currency=CURR3,application=APP2,env=ENV),
metric2(currency=CURR1,application=APP1,env=ENV),
metric3(currency=CURR1,application=APP1,env=ENV)
I am trying to do certain arithmetic operations with the metrics in Grafana, such as (metric1 – (metric2 + metric3)) / metric1. For CURR1 it works, as I have all the metrics. For CURR2 and 3 it doesn’t because I am missing either metric2 and metric3 or both. This is a simplified version of my setup.
I tried to use or vector(0) for all metrics, but it still doesn’t show the result only if all metrics exist. Ex:
(metric1 – ((metric2 or vector(0)) + (metric3 or vector(0)) / metric1 -> this will only print the result for CURR1
I also tried using or clamp_max(absent(notExists{currency=CURR1, env=ENV, application=APP1),0)
If for CURR2 I only have metric1, I want the calculation to be made and show the result 1. I am displaying the data as a table in Grafana.