Query multiple metrics in one Prometheus HTTP Call

Viewed 2522

I want to make one http call to Prometheus server and get the following:

  • Multiple metrics
  • Calculate rate for all metrics within last 30 seconds

I have the following query which works, it requests the results of multiple prometheus metrics in one call for last 30 seconds. I`m just not sure how to extend this query to also calculate the rate for all these metrics. Can anyone help?

/api/v1/query?query={__name__=~"metric1|metric2|metric3",service=~"testservice"}[30s]

I want to do something like

    /api/v1/query?query={rate(__name__=~"metric1|metric2|metric3",service=~"testservice"}[30s])
1 Answers

You need to put the rate before the labels. This should work:

/api/v1/query?query=rate({__name__=~"metric1|metric2|metric3",service=~"testservice"}[30s])

Note that you must have at least one datapoint in the 30s period for each of the metrics.

Related