The provided query is valid MetricsQL query for VictoriaMetrics, but unfortunately it doesn't work in the original PromQL.
Prometheus provides topk
and bottomk operators, which can be used for limiting the number of returned time series. Unfortunately, these operators limit the number of returned time series on a per-point basis (considering points on the graph). This means that the total number of returned time series may exceed the requested limit. MetricsQL solve this issue with a family of topk_* and bottomk_* functions. See MetricsQL docs for details.
Robust Perception
robustperception.io › limiting-promql-resource-usage
Limiting PromQL resource usage – Robust Perception | Prometheus Monitoring Experts
The more efficient PromQL implementation actually caused a few out of memory issues, as previously some large slow queries were hitting the timeout but were now quickly eating up memory! The most recent addition was in Prometheus 2.5.0, a limit on how many samples a PromQL query can have in memory at once.
Prometheus
discuss.prometheus.io › promql
Limit the number of results in a range vector? - PromQL - Prometheus Monitoring System
August 1, 2024 - Hello, I am trying to limit the results returned in range vector. I tried using topk to limit my return but it is returning more than n specified. I found this on the web: This is because it returns top N time series independently per each timestamp on the graph. docs Here is an example of ...
Medium
medium.com › @yogeshkolhatkar › prometheus-querying-best-practices-a-complete-guide-a2f0b2899a93
Prometheus Querying Best Practices: A Complete Guide | by Yogesh Kolhatkar | Medium
March 22, 2025 - High-cardinality metrics increase storage and processing time. Limit the number of unique label values. Subqueries allow breaking down large queries into manageable chunks. ... Prometheus and PromQL are powerful tools for querying time-series data. Following best practices such as optimizing ...
Prometheus
prometheus.io › docs › prometheus › latest › querying › functions
Query functions | Prometheus
This function has to be enabled via the feature flag --enable-feature=promql-experimental-functions.
pint
cloudflare.github.io › pint › checks › promql › range_query.html
promql/range_query | pint
This check inspects range query selectors on all queries. It will warn if a query tries to request a time range that is bigger than Prometheus retention limits.
Last9
last9.io › blog › promql-cheat-sheet
PromQL Cheat Sheet: Queries, Functions, and Labels | Last9
September 12, 2024 - This cheat sheet collects practical PromQL snippets organized by use case — from quick incident queries to advanced aggregation, label manipulation, and capacity planning. When everything’s on fire and you need to know what’s going on ASAP: sum(rate(http_requests_total[5m])) by (status_code) This gives you a quick snapshot of HTTP requests broken down by status code. ... This limits the result to the top 5 status codes, reducing noise in busy environments.
New Relic
docs.newrelic.com › docs › infrastructure › prometheus-integrations › view-query-data › supported-promql-features
Supported PromQL features | New Relic Documentation
In all cases, we enforce a limit of 366 steps in range queries. We also return only 100 time series from queries by default. If you want to see more (or fewer), you need to explicitly add a topk() to your query. (Note that the topk() implementation in our PromQL-style query is different from ...
Sysdig Docs
docs.sysdig.com › en › limit-prometheus-metric-collection.html
Collect Prometheus Metrics | Sysdig Docs
May 16, 2020 - The time series from all the endpoints are sent to the backend in order to prevent data integrity issues. Therefore, if total number of time series from a particular endpoint is greater than the maximum allowed limit by any agent, the time series from that endpoint will be dropped irrespective of whether dynamic sampling is turned on or not.
Prometheus
prometheus.io › docs › prometheus › latest › querying › operators
Operators | Prometheus
limit_ratio(r, v) (sample a pseudo-random ratio r of elements, experimental, must be enabled with --enable-feature=promql-experimental-functions)
Medium
valyala.medium.com › how-to-optimize-promql-and-metricsql-queries-85a1b75bf986
How to optimize PromQL in Prometheus | Medium
October 29, 2021 - Usually the number of processed raw samples matches the number of selected raw samples. But sometimes the number of processed raw samples may significantly exceed the number of selected raw samples. PromQL and MetricsQL can process the same raw sample multiple times if the following conditions are met:
Google Groups
groups.google.com › g › prometheus-users › c › Evum5I8ARDs
Calculate Max over time on Sum function
July 13, 2017 - PromQL currently only supports constructing a range vector from a time series, but not from the result of an expression. Recording a new time series is a workaround that for now. Here is the longstanding issue for that limitation: https://github.com/prometheus/prometheus/issues/1227