PromQL/Victoria Metrics - multiply time series with different resolutions

980 views Asked by At

I have a question on promql series multiplication. I have 2 time series, that have a different sampling (5minutes and 15 minutes). I need to bring them at the same resolution, multiply and sum

Something like:

WITH (
  filter1= {testID=~"test2"},
  metric0 = myMetric1{filter1},
  metric1 = myMetric2{filter1}
)
sum_over_time(metric0[15m]*metric0[15m])&step=1h

This is not working, but output would be:

  • bring metric1 and metric2 at the same resolution (15min)
  • multiply sample by sample
  • aggregate (sum) at 1h

Is this possible?

Thanks!

1

There are 1 answers

0
valyala On BEST ANSWER

Try the following MetricsQL query:

with (
  filter = {testID=~"test2"},
  metric1 = myMetric1{filter},
  metric2 = myMetric2{filter},
)
sum_over_time((metric1 * metric2)[1h:15m])

This query relies on Prometheus subqueries for bringing metric1 and metric2 to the same resolution - 15 minutes before summing their multiplication over the last hour.

Note that it is expected that the time series matching metric1 and metric2 have identical set of labels. Otherwise empty result will be returned. If this isn't the case, then the multiplication may require additional modifiers such as on, ignoring, group_left or group_right - see https://prometheus.io/docs/prometheus/latest/querying/operators/#vector-matching for details.