<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Query metric data from Grafana Mimir on Grafana Labs</title><link>https://grafana.com/docs/mimir/v3.1.x/query/</link><description>Recent content in Query metric data from Grafana Mimir on Grafana Labs</description><generator>Hugo -- gohugo.io</generator><language>en</language><atom:link href="/docs/mimir/v3.1.x/query/index.xml" rel="self" type="application/rss+xml"/><item><title>Best practices for querying Grafana Mimir</title><link>https://grafana.com/docs/mimir/v3.1.x/query/query-best-practices/</link><pubDate>Wed, 03 Jun 2026 09:01:40 +0200</pubDate><guid>https://grafana.com/docs/mimir/v3.1.x/query/query-best-practices/</guid><content><![CDATA[&lt;h1 id=&#34;best-practices-for-querying-grafana-mimir&#34;&gt;Best practices for querying Grafana Mimir&lt;/h1&gt;
&lt;p&gt;The way you write queries for Grafana Mimir affects the speed and quality of your results. Follow these best practices to ensure optimal performance and reliability for queries.&lt;/p&gt;
&lt;h2 id=&#34;use-label-matchers&#34;&gt;Use label matchers&lt;/h2&gt;
&lt;p&gt;To reduce the initial size of your dataset, apply label matchers to your query. Label matchers help you to filter your data based on its associated labels. For example, if you have a label called &lt;code&gt;app_name&lt;/code&gt;, you can append &lt;code&gt;app_name=&amp;quot;myapp&amp;quot;&lt;/code&gt; to your query.&lt;/p&gt;
&lt;p&gt;Whenever possible, use an exact label match, such as &lt;code&gt;label=&amp;quot;value&amp;quot;&lt;/code&gt;, instead of a regular expression, such as &lt;code&gt;label=~&amp;quot;pattern&amp;quot;&lt;/code&gt;. Regular expressions are more computationally expensive.&lt;/p&gt;
&lt;p&gt;For more information about how to query metric labels, refer to 
    &lt;a href=&#34;/docs/mimir/v3.1.x/query/query-metric-labels/&#34;&gt;Query metric labels&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;narrow-down-your-time-range&#34;&gt;Narrow down your time range&lt;/h2&gt;
&lt;p&gt;Limit your query to a specific time period to reduce the number of metrics and samples Mimir needs to process. As a best practice, query the shortest feasible time range to narrow down your results. Larger time ranges require more computing resources and increase query latency.&lt;/p&gt;
&lt;p&gt;Follow these guidelines for setting a time range based on your query type:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Dashboards: For dashboards, use a time range that matches the typical viewing window. While users can zoom out to view more history, the default view should be efficient and focused on recent, relevant data.&lt;/li&gt;
&lt;li&gt;Alerting rules: Alerting rules should almost always operate on short, recent time windows to detect current states or recent trends, rather than long-term historical patterns. Timely alerts depend on the quick evaluations of fresh data.&lt;/li&gt;
&lt;li&gt;Ad-hoc analysis: When exploring data, start with small time ranges and gradually expand if more historical context is required for your investigation. This iterative approach prevents unnecessary strain on the system during exploratory phases.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Additionally, choose a step interval that matches your requirements for running the query. Smaller step intervals increase a query&amp;rsquo;s cost but provide higher resolution.&lt;/p&gt;
&lt;h2 id=&#34;consider-your-query-evaluation-frequency-and-time-range&#34;&gt;Consider your query evaluation frequency and time range&lt;/h2&gt;
&lt;p&gt;Consider the evaluation frequency of your query when determining the time range. For instance, if a query runs every minute, such as for an alerting rule or a frequently refreshing dashboard panel, there&amp;rsquo;s no need for it to look back over a long time period, such as 30 days.&lt;/p&gt;
&lt;p&gt;Queries with very long look-back periods, such as &lt;code&gt;rate(my_metric[30d])&lt;/code&gt;, can be computationally expensive. They require Mimir to process a large volume of historical data, even if only the latest value is of interest.&lt;/p&gt;
&lt;h2 id=&#34;filter-early-in-the-query&#34;&gt;Filter early in the query&lt;/h2&gt;
&lt;p&gt;Avoid running broad, large-scale queries and then filtering the results within Grafana. This approach is computationally expensive and inefficient. Instead, filter your data as early as possible in the query itself.&lt;/p&gt;
&lt;p&gt;Filtering data in the query provides the following benefits:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Reduced data transfer: Filtering at the query level means Mimir sends only the data you need to Grafana, which reduces network overhead.&lt;/li&gt;
&lt;li&gt;Lower processing load: Mimir can apply filters at the storage layer, allowing it to discard irrelevant time series and data points before they are retrieved, processed, and aggregated. This significantly reduces the computational load on the Mimir cluster.&lt;/li&gt;
&lt;li&gt;Improved query speed: Queries that are pre-filtered are generally faster to run and return results.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Use these strategies to implement early filtering:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Use label selectors: Leverage precise label selectors within your PromQL query to narrow down the dataset from the start. For more information, refer to &lt;a href=&#34;#use-label-selectors&#34;&gt;Use Label Selectors&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Apply functions and aggregations: If you need to transform or aggregate data, do so within the query. For example, &lt;code&gt;sum by (job) (metric_name)&lt;/code&gt; is more efficient than retrieving all &lt;code&gt;metric_name&lt;/code&gt; series and then summing them in Grafana.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;use-recording-rules&#34;&gt;Use recording rules&lt;/h2&gt;
&lt;p&gt;If you need to run a particularly expensive or complex query, consider creating a recording rule to minimize its load. Recording rules in Mimir involve precomputing queries at a predetermined time and then saving the results for faster retrieval later.&lt;/p&gt;
&lt;p&gt;Recording rules are useful for the following types of queries:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Dashboard queries that run frequently&lt;/li&gt;
&lt;li&gt;Complex aggregations across high-cardinality metrics&lt;/li&gt;
&lt;li&gt;Queries spanning long time ranges&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Recording rules are most beneficial for queries with results that you frequently evaluate. If you use a recording rule for a query and don&amp;rsquo;t frequently evaluate its results, it could lead to unnecessary computation and data storage.&lt;/p&gt;
&lt;p&gt;For more information about recording rules, refer to &lt;a href=&#34;https://prometheus.io/docs/prometheus/latest/configuration/recording_rules/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Defining recording rules&lt;/a&gt; in the Prometheus documentation.&lt;/p&gt;
]]></content><description>&lt;h1 id="best-practices-for-querying-grafana-mimir">Best practices for querying Grafana Mimir&lt;/h1>
&lt;p>The way you write queries for Grafana Mimir affects the speed and quality of your results. Follow these best practices to ensure optimal performance and reliability for queries.&lt;/p></description></item><item><title>Query metric labels</title><link>https://grafana.com/docs/mimir/v3.1.x/query/query-metric-labels/</link><pubDate>Wed, 03 Jun 2026 09:01:40 +0200</pubDate><guid>https://grafana.com/docs/mimir/v3.1.x/query/query-metric-labels/</guid><content><![CDATA[&lt;h1 id=&#34;query-metric-labels&#34;&gt;Query metric labels&lt;/h1&gt;
&lt;p&gt;Grafana Mimir supports multiple &lt;a href=&#34;../../references/http-api/&#34;&gt;HTTP API&lt;/a&gt; endpoints to query metric label names and values.
There are differences and trade-off between these API endpoints.&lt;/p&gt;
&lt;h2 id=&#34;querying-label-names&#34;&gt;Querying label names&lt;/h2&gt;
&lt;p&gt;The following API endpoints find the list of label names of all (or a subset of) series stored in Mimir:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href=&#34;../../references/http-api/#get-label-names&#34;&gt;Get label names&lt;/a&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;code&gt;GET,POST &amp;lt;prometheus-http-prefix&amp;gt;/api/v1/labels&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href=&#34;../../references/http-api/#label-names-cardinality&#34;&gt;Label names cardinality&lt;/a&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;code&gt;GET,POST &amp;lt;prometheus-http-prefix&amp;gt;/api/v1/cardinality/label_names&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;prometheus-http-prefix&amp;gt;&lt;/code&gt; is the Prometheus HTTP prefix as documented in the &lt;a href=&#34;../../references/http-api/#path-prefixes&#34;&gt;HTTP API&lt;/a&gt; reference.
The default prefix is &lt;code&gt;/prometheus&lt;/code&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;h3 id=&#34;recommendations-and-performance-trade-off&#34;&gt;Recommendations and performance trade-off&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Prefer &lt;em&gt;get label names&lt;/em&gt; over &lt;em&gt;label names cardinality&lt;/em&gt; API, unless you need to know the number of unique label values for each label name.&lt;/li&gt;
&lt;li&gt;The &lt;em&gt;get label names&lt;/em&gt; API &lt;code&gt;start&lt;/code&gt; and &lt;code&gt;end&lt;/code&gt; parameters are optional. When omitted, Mimir will query label names for the whole retention period or up to the configured &lt;code&gt;-store.max-labels-query-length&lt;/code&gt;. We recommend to always specify &lt;code&gt;start&lt;/code&gt; and &lt;code&gt;end&lt;/code&gt; parameters, and preferably set them to the shortest period that is feasible for your use case.&lt;/li&gt;
&lt;li&gt;For both API endpoints, executing a request specifying the series selector is computationally more expensive than the same request without the series selector. However, the results set might be significantly smaller when the series selector reduces the series set.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;features-comparison&#34;&gt;Features comparison&lt;/h3&gt;
&lt;p&gt;The different API endpoints have different features, and the main differences follow.&lt;/p&gt;
&lt;h4 id=&#34;can-specify-the-time-range-in-the-request&#34;&gt;Can specify the time range in the request?&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Get label names&lt;/strong&gt;&lt;br /&gt;
Yes. However, the actual time range granularity is restricted to TSDB block range periods, which are &lt;code&gt;2h&lt;/code&gt; for the most recent metrics, and up to &lt;code&gt;24h&lt;/code&gt; for historical metrics when running Mimir with the default configuration.
In practice, the input &lt;code&gt;start&lt;/code&gt; and &lt;code&gt;end&lt;/code&gt; parameters are rounded to the TSDB block boundaries:
&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;start&lt;/code&gt; parameter is rounded to the start of the nearest block containing samples with timestamps that are greater than or equal to the input timestamp.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;end&lt;/code&gt; parameter is rounded to the end of the nearest block containing samples with timestamps that are less than or equal to the input timestamp.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Label names cardinality&lt;/strong&gt;&lt;br /&gt;
No. The API queries only the in-memory series in the ingesters that hold series for the tenant.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;can-specify-the-series-selector-in-the-request&#34;&gt;Can specify the series selector in the request?&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Get label names API&lt;/strong&gt;&lt;br /&gt;
Yes. The optional &lt;code&gt;match[]&lt;/code&gt; parameter makes it possible to select the series from which to read the label names. The &lt;code&gt;match[]&lt;/code&gt; parameter can be specified multiple times. When omitted, label names are extracted from all series.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Label names cardinality API&lt;/strong&gt;&lt;br /&gt;
Yes. The optional &lt;code&gt;selector&lt;/code&gt; parameter makes it possible to select the series from which to read the label names. The &lt;code&gt;selector&lt;/code&gt; parameter can be specified only once. When omitted, label names are extracted from all series.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;querying-label-values&#34;&gt;Querying label values&lt;/h2&gt;
&lt;p&gt;The following API endpoints find the list of label values for a given label name:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href=&#34;../../references/http-api/#get-label-values&#34;&gt;Get label values&lt;/a&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;code&gt;GET &amp;lt;prometheus-http-prefix&amp;gt;/api/v1/label/{name}/values&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href=&#34;../../references/http-api/#label-values-cardinality&#34;&gt;Label values cardinality&lt;/a&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;code&gt;GET,POST &amp;lt;prometheus-http-prefix&amp;gt;/api/v1/cardinality/label_values&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;prometheus-http-prefix&amp;gt;&lt;/code&gt; is the Prometheus HTTP prefix as documented in the &lt;a href=&#34;../../references/http-api/#path-prefixes&#34;&gt;HTTP API&lt;/a&gt; reference.
The default prefix is &lt;code&gt;/prometheus&lt;/code&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;h3 id=&#34;recommendations-and-performance-trade-off-1&#34;&gt;Recommendations and performance trade-off&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Prefer &lt;em&gt;get label values&lt;/em&gt; over &lt;em&gt;label values cardinality&lt;/em&gt; API, unless you need to know the number of series for each label name and value.&lt;/li&gt;
&lt;li&gt;The &lt;em&gt;get label values&lt;/em&gt; API makes it possible to specify a single label name, and the &lt;em&gt;label values cardinality&lt;/em&gt; API makes it possible to specify multiple label names. If you need to get the label values for multiple label names, we recommend issuing multiple &lt;em&gt;get label values&lt;/em&gt; requests instead of a single &lt;em&gt;label values cardinality&lt;/em&gt; API call with multiple label names.&lt;/li&gt;
&lt;li&gt;The &lt;em&gt;get label values&lt;/em&gt; API &lt;code&gt;start&lt;/code&gt; and &lt;code&gt;end&lt;/code&gt; parameters are optional. When omitted, Mimir will query label values for the whole retention period or up to the configured &lt;code&gt;-store.max-labels-query-length&lt;/code&gt;. We recommend to always specify &lt;code&gt;start&lt;/code&gt; and &lt;code&gt;end&lt;/code&gt; parameters, and preferably set them to the shortest period that is feasible for your use case. The longer the time range, the more computationally expensive the request is.&lt;/li&gt;
&lt;li&gt;For both API endpoints, executing a request specifying the series selector is computationally more expensive than the same request without the series selector. However, the results set might be significantly smaller when the series selector reduces the series set.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;features-comparison-1&#34;&gt;Features comparison&lt;/h3&gt;
&lt;p&gt;The different API endpoints have different features, and the main differences follow.&lt;/p&gt;
&lt;h4 id=&#34;can-specify-the-time-range-in-the-request-1&#34;&gt;Can specify the time range in the request?&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Get label values API&lt;/strong&gt;&lt;br /&gt;
Yes. However, the actual time range granularity is restricted to TSDB block range periods, which are &lt;code&gt;2h&lt;/code&gt; for the most recent metrics, and up to &lt;code&gt;24h&lt;/code&gt; for historical metrics when running Mimir with the default configuration.
In practice, the input &lt;code&gt;start&lt;/code&gt; and &lt;code&gt;end&lt;/code&gt; parameters are rounded to the TSDB block boundaries:
&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;start&lt;/code&gt; parameter is rounded to the start of the nearest block containing samples with timestamps that are greater than or equal to the input timestamp.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;end&lt;/code&gt; parameter is rounded to the end of the nearest block containing samples with timestamps that are less than or equal to the input timestamp.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Label values cardinality API&lt;/strong&gt;&lt;br /&gt;
No. The API queries only the in-memory series in the ingesters that hold series for the tenant.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;can-specify-the-series-selector-in-the-request-1&#34;&gt;Can specify the series selector in the request?&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Get label values API&lt;/strong&gt;&lt;br /&gt;
Yes. The optional &lt;code&gt;match[]&lt;/code&gt; parameter makes it possible to select the series from which to read the label values. The &lt;code&gt;match[]&lt;/code&gt; parameter can be specified multiple times. When omitted, label values are extracted from all series.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Label values cardinality API&lt;/strong&gt;&lt;br /&gt;
Yes. The optional &lt;code&gt;selector&lt;/code&gt; parameter makes it possible to select the series from which to read the label names and values. The &lt;code&gt;selector&lt;/code&gt; parameter can be specified only once. When omitted, label names and values are extracted from all series.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;alternatives&#34;&gt;Alternatives&lt;/h2&gt;
&lt;p&gt;The following API endpoints have not been explicitly designed to query metric label names and values, but label names and/or values can be extracted from the response:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href=&#34;../../references/http-api/#get-series-by-label-matchers&#34;&gt;Get series by label matchers&lt;/a&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;code&gt;GET,POST &amp;lt;prometheus-http-prefix&amp;gt;/api/v1/series&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href=&#34;../../references/http-api/#instant-query&#34;&gt;Instant query&lt;/a&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;code&gt;GET,POST &amp;lt;prometheus-http-prefix&amp;gt;/api/v1/query&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;prometheus-http-prefix&amp;gt;&lt;/code&gt; is the Prometheus HTTP prefix as documented in the &lt;a href=&#34;../../references/http-api/#path-prefixes&#34;&gt;HTTP API&lt;/a&gt; reference.
The default prefix is &lt;code&gt;/prometheus&lt;/code&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;h3 id=&#34;recommendations-and-performance-trade-off-2&#34;&gt;Recommendations and performance trade-off&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Prefer &lt;em&gt;get label names&lt;/em&gt; over other APIs to get the list of label names. The &lt;em&gt;get label names&lt;/em&gt; is expected to always perform better than other APIs.&lt;/li&gt;
&lt;li&gt;Prefer &lt;em&gt;get label values&lt;/em&gt; over other APIs to get the list of label values.
&lt;ul&gt;
&lt;li&gt;If you&amp;rsquo;re experiencing a slow response time when querying &lt;em&gt;get label values&lt;/em&gt; API, the request includes a series selector and the series selector is expected to match a small set of series (order of few thousands), then consider using &lt;em&gt;get series by label matchers&lt;/em&gt; instead of the &lt;em&gt;get label values&lt;/em&gt; API.&lt;/li&gt;
&lt;li&gt;If you can&amp;rsquo;t use &lt;em&gt;get series by label matchers&lt;/em&gt; API (e.g. the API is not available in the client you&amp;rsquo;re using), then fallback to the &lt;em&gt;instant query&lt;/em&gt; API.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
]]></content><description>&lt;h1 id="query-metric-labels">Query metric labels&lt;/h1>
&lt;p>Grafana Mimir supports multiple &lt;a href="../../references/http-api/">HTTP API&lt;/a> endpoints to query metric label names and values.
There are differences and trade-off between these API endpoints.&lt;/p></description></item></channel></rss>