Search code examples
prometheuspromql

How to divide two by prometheus queries to calculate a percentage


I have two distinct metrics that both have a label of client_app.

One metric is a histogram that counts the number of failed requests for a given time span (i.e. 10 req in the last min failed) and the other metric is a counter that increments for every request.

I want to divide these two metrics to get a percentage of failed requests per client_app

Here is my attempt so far

avg by (client_app) (max(rate(ignored_events_sum[5m])) / sum(rate(total_app_events[5m])))

This only outputs a single graph whereas I am hoping for one per each client_app


Solution

  • Try this:

    max by (client_app) (rate(ignored_events_sum[5m])) / sum by (client_app) (rate(total_app_events[5m]))