# Prometheus PromQL max\_over\_time for multiple metrics with different names

**URL:** <https://discuss.prometheus.io/t/prometheus-promql-max-over-time-for-multiple-metrics-with-different-names/823>\
**Category:** PromQL\
**Created:** [March 2, 2022, 6:11pm UTC](https://discuss.prometheus.io/t/prometheus-promql-max-over-time-for-multiple-metrics-with-different-names/823 "2022-03-02T18:11:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![richard.crist](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.prometheus.io/richard.crist/32/374_2.png) [@richard.crist](https://discuss.prometheus.io/u/richard.crist)\
**Post date:** [March 2, 2022, 6:11pm UTC](https://discuss.prometheus.io/t/prometheus-promql-max-over-time-for-multiple-metrics-with-different-names/823/1 "2022-03-02T18:11:16Z")

</div>

In Prometheus PromQL I can do the following:

{ **name** =~“oracledb\_ohlprod\_conn\_count\_.”}

And I get the following:

| ELEMENT | VALUE |
| --- | --- |
| oracledb\_ohlprod\_conn\_count\_1{host=“10.223.16.30”,instance=“10.223.16.30:9163”,job=“oracledb\_exporter”} | 1234 |
| oracledb\_ohlprod\_conn\_count\_2{host=“10.223.16.30”,instance=“10.223.16.30:9163”,job=“oracledb\_exporter”} | 1272 |

I can also do the following:

max({ **name** =~“oracledb\_ohlprod\_conn\_count\_.”})

And I get the following (slightly different data as some time has went by):

| ELEMENT | VALUE |
| --- | --- |
| {} | 1257 |

But if I do something like the following (range outside parens):

max\_over\_time({ **name** =~“oracledb\_ohlprod\_conn\_count\_.”})[3h]

I get the error:

Error executing query: invalid parameter ‘query’: 1:59: parse error: ranges only allowed for vector selectors

And if I do the following (range inside parens):

max\_over\_time({ **name** =~“oracledb\_ohlprod\_conn\_count\_.”}[3h])

I ge the error:

Error executing query: vector cannot contain metrics with the same labelset

BOTTOM LINE:

I am trying to get the max over time of different named metrics.

Not differently qualified metrics of same name, but max over time of multiple metrics with different names.

Something like “get the max over time for given range for each metric, then get the max of those results”.

I am not sure if this is possible in PromQL, or if it is possible and I have not found the right documentation or understood the right documentation.

All help is appreciated! Thank you!

---

<div class="post-metadata">

**Author:** ![richard.crist](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.prometheus.io/richard.crist/32/374_2.png) [@richard.crist](https://discuss.prometheus.io/u/richard.crist)\
**Post date:** [March 4, 2022, 10:53pm UTC](https://discuss.prometheus.io/t/prometheus-promql-max-over-time-for-multiple-metrics-with-different-names/823/2 "2022-03-04T22:53:21Z")

</div>

Ok I finally found the solution here: [kubernetes - Calculate Max over time on sum function in Prometheus - Stack Overflow](https://stackoverflow.com/questions/45070018/calculate-max-over-time-on-sum-function-in-prometheus)

For me the implementation was:  
max\_over\_time(max({ **name** =~“oracledb\_. _? maxqcount [^r]._ ”})[$\_\_range:1m])

Basically above says:  
Use name lookup to get list of matching label names  
Take max across those names  
Use PromQL subquery to then take max of those for the currently selected dashboard range at resolution interval of 1 minute
