Search code examples
grafanaprometheuspromql

Select largest label value in Prometheus query


I have a Prometheus and Grafana instance set up where I want to query a specific property called "upsAdvBatteryRecommendedReplaceDate".

Prometheus successfully returns a response when querying this property as can be seen here: upsAdvBatteryRecommendedReplaceDate in Prometheus

However, the result consists of two time series (one with the upsAdvBatteryRecommendedReplaceDate="12/11/2021" and the other with upsAdvBatteryRecommendedReplaceDate="12/10/2021").

This becomes a problem as soon as I set up a singlestat in Grafana displaying the upsAdvBatteryRecommendedReplaceDate label of the upsAdvBatteryRecommendedReplaceDate query. This will lead to a "Multiple Series Error" as can be seen here: upsAdvBatteryRecommendedReplaceDate in Grafana

It works as expected if I change the Grafana time range to e.g. "Last 15 minutes" as it can be seen here: upsAdvBatteryRecommendedReplaceDate in Grafana with proper replacement date

So my question is: Is there a way to select/extract only the time series with the most recent/latest label value for "upsAdvBatteryRecommendedReplaceDate" so that, in this case, only the time series where upsAdvBatteryRecommendedReplaceDate="12/11/2021" shows up?

Thank you!


Solution

  • Maybe this will help other people out as well: I resolved it by simply checking the "Instant" checkbox of the singlestat in the grafana dashboard.