<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Create recording rules on Grafana Labs</title><link>https://grafana.com/docs/grafana/v11.4/alerting/alerting-rules/create-recording-rules/</link><description>Recent content in Create recording rules on Grafana Labs</description><generator>Hugo -- gohugo.io</generator><language>en</language><atom:link href="/docs/grafana/v11.4/alerting/alerting-rules/create-recording-rules/index.xml" rel="self" type="application/rss+xml"/><item><title>Create Grafana-managed recording rules</title><link>https://grafana.com/docs/grafana/v11.4/alerting/alerting-rules/create-recording-rules/create-grafana-managed-recording-rules/</link><pubDate>Thu, 05 Dec 2024 18:25:49 +0000</pubDate><guid>https://grafana.com/docs/grafana/v11.4/alerting/alerting-rules/create-recording-rules/create-grafana-managed-recording-rules/</guid><content><![CDATA[&lt;h1 id=&#34;create-grafana-managed-recording-rules&#34;&gt;Create Grafana-managed recording rules&lt;/h1&gt;
&lt;p&gt;
    &lt;a href=&#34;/docs/grafana/v11.4/alerting/alerting-rules/create-recording-rules/&#34;&gt;Recording rules&lt;/a&gt; allow you to periodically pre-compute frequently used or computationally expensive queries, saving the results as a new time series metric.&lt;/p&gt;
&lt;p&gt;Alert rules and dashboards can then query the new metric resulting from the recording rule. This is faster than querying real-time data and can help to reduce system load.&lt;/p&gt;
&lt;p&gt;Grafana does not contain an embedded time-series database to store recording rule results. You must bring your own Prometheus-compatible database to store the series generated by recording rules.&lt;/p&gt;
&lt;p&gt;Grafana-managed recording rules offer the same Prometheus-like semantics but allow you to query 
    &lt;a href=&#34;/docs/grafana/v11.4/alerting/fundamentals/alert-rules/#supported-data-sources&#34;&gt;data sources supported by alerting&lt;/a&gt;. Additionally, you can use recording rules to import and map data from other data sources into Prometheus.&lt;/p&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;Grafana-managed recording rules are enabled by default in Grafana Cloud.&lt;/p&gt;
&lt;p&gt;In Grafana OSS and Enterprise, you must enable them by following the &lt;a href=&#34;#before-you-begin&#34;&gt;Before you begin&lt;/a&gt; instructions.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;p&gt;To configure Grafana-managed recording rules, complete the following steps.&lt;/p&gt;
&lt;h2 id=&#34;before-you-begin&#34;&gt;Before you begin&lt;/h2&gt;
&lt;p&gt;This section only applies to Grafana OSS and Grafana Enterprise.&lt;/p&gt;
&lt;p&gt;First, enable the &lt;code&gt;grafanaManagedRecordingRules&lt;/code&gt; 
    &lt;a href=&#34;/docs/grafana/v11.4/setup-grafana/configure-grafana/feature-toggles/&#34;&gt;feature flag&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Then, enable the feature by setting &lt;code&gt;enabled = true&lt;/code&gt; in the &lt;code&gt;[recording_rules]&lt;/code&gt; section of the Grafana config .ini. Provide the URL of your Prometheus-compatible remote-write endpoint in the &lt;code&gt;url&lt;/code&gt; field, along with optional credentials or headers.&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;[recording_rules]
enabled = true
url = http://my-example-prometheus.local:9090/api/prom/push
basic_auth_username = my-user
basic_auth_password = my-pass

[recording_rules.custom_headers]
X-My-Header = MyValue&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;add-new-recording-rule&#34;&gt;Add new recording rule&lt;/h2&gt;
&lt;p&gt;To create a new Grafana-managed recording rule:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Click &lt;strong&gt;Alerts &amp;amp; IRM&lt;/strong&gt; -&amp;gt; &lt;strong&gt;Alerting&lt;/strong&gt; -&amp;gt;
&lt;strong&gt;Alert rules&lt;/strong&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Scroll to the &lt;strong&gt;Grafana-managed section&lt;/strong&gt; and click &lt;strong&gt;&#43;New recording rule&lt;/strong&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Enter the names to identify your recording rule and metric.&lt;/p&gt;
&lt;p&gt;The metric name must be a Prometheus metric name and contain no whitespace. For details, refer to &lt;a href=&#34;https://prometheus.io/docs/concepts/data_model/#metric-names-and-labels&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Prometheus metric names&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;define-recording-rule&#34;&gt;Define recording rule&lt;/h2&gt;
&lt;p&gt;Define a query to get the data you want to measure and set the recording rule output.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Select a data source.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;From the &lt;strong&gt;Options&lt;/strong&gt; dropdown, specify a time range.&lt;/p&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;Grafana Alerting only supports fixed relative time ranges, for example, &lt;code&gt;now-24hr: now&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;It does not support absolute time ranges: &lt;code&gt;2021-12-02 00:00:00 to 2021-12-05 23:59:592&lt;/code&gt; or semi-relative time ranges: &lt;code&gt;now/d to: now&lt;/code&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Add a query.&lt;/p&gt;
&lt;p&gt;To add multiple queries, click &lt;strong&gt;Add query&lt;/strong&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Add one or more 
    &lt;a href=&#34;/docs/grafana/v11.4/alerting/fundamentals/alert-rules/queries-conditions/#expression-queries&#34;&gt;expressions&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;a. For each expression, select either &lt;strong&gt;Classic condition&lt;/strong&gt; to create a single recording rule, or choose from the &lt;strong&gt;Math&lt;/strong&gt;, &lt;strong&gt;Reduce&lt;/strong&gt;, and &lt;strong&gt;Resample&lt;/strong&gt; options.&lt;/p&gt;
&lt;p&gt;When using Prometheus, you can use an instant vector and built-in functions, so you don&amp;rsquo;t need to add additional expressions.&lt;/p&gt;
&lt;p&gt;b. Click &lt;strong&gt;Preview&lt;/strong&gt; to verify that the expression is successful.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Click &lt;strong&gt;Set as recording rule output&lt;/strong&gt; on the query or expression you want to set as your rule output.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;set-evaluation-behavior&#34;&gt;Set evaluation behavior&lt;/h2&gt;
&lt;p&gt;Use recording rule evaluation to determine how frequently a recording rule should be evaluated.&lt;/p&gt;
&lt;p&gt;To do this, you need to make sure that your recording rule is in the right evaluation group with an interval that works best for your use case.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Select a folder or click &lt;strong&gt;&#43; New folder&lt;/strong&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Select an evaluation group or click &lt;strong&gt;&#43; New evaluation group&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;If you are creating a new evaluation group, specify the interval for the group.&lt;/p&gt;
&lt;p&gt;All rules within the same group are evaluated concurrently over the same time interval. Every recording rule in a group uses the same evaluation time, meaning that all queries from the same group are always aligned with each other.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Before or after creating a recording rule, you have the option to &lt;strong&gt;Pause evaluation&lt;/strong&gt; if necessary.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;advanced-configuration&#34;&gt;Advanced configuration&lt;/h3&gt;
&lt;p&gt;
    &lt;a href=&#34;/docs/grafana/v11.4/setup-grafana/configure-grafana/#min_interval&#34;&gt;min_interval&lt;/a&gt; sets the minimum interval to enforce between rule evaluations. The default value is 10s which equals the scheduler interval. Rules are adjusted if they are less than this value or if they are not multiple of the scheduler interval (10s). Higher values can help with resource management as fewer evaluations are scheduled over time.&lt;/p&gt;
&lt;p&gt;This setting has precedence over each individual rule frequency. If a rule frequency is lower than this value, then this value is enforced.&lt;/p&gt;
&lt;p&gt;This setting applies to both Grafana-managed alert and recording rules.&lt;/p&gt;
&lt;h2 id=&#34;add-labels&#34;&gt;Add labels&lt;/h2&gt;
&lt;p&gt;Optionally, you can add custom labels to the resulting metric by selecting existing key-value pairs from the drop down or entering the new key or value.&lt;/p&gt;
&lt;h2 id=&#34;query-the-new-metric-in-dashboards-or-alert-rules&#34;&gt;Query the new metric in dashboards or alert rules&lt;/h2&gt;
&lt;p&gt;Click &lt;strong&gt;Save rule&lt;/strong&gt; or &lt;strong&gt;Save rule and exit&lt;/strong&gt; to save the rule.&lt;/p&gt;
&lt;p&gt;Once saved, the new recording metric is available for use in dashboards and alert rules.&lt;/p&gt;
]]></content><description>&lt;h1 id="create-grafana-managed-recording-rules">Create Grafana-managed recording rules&lt;/h1>
&lt;p>
&lt;a href="/docs/grafana/v11.4/alerting/alerting-rules/create-recording-rules/">Recording rules&lt;/a> allow you to periodically pre-compute frequently used or computationally expensive queries, saving the results as a new time series metric.&lt;/p></description></item><item><title>Create data source-managed recording rules</title><link>https://grafana.com/docs/grafana/v11.4/alerting/alerting-rules/create-recording-rules/create-data-source-managed-recording-rules/</link><pubDate>Mon, 16 Dec 2024 11:24:34 +0000</pubDate><guid>https://grafana.com/docs/grafana/v11.4/alerting/alerting-rules/create-recording-rules/create-data-source-managed-recording-rules/</guid><content><![CDATA[&lt;h1 id=&#34;create-data-source-managed-recording-rules&#34;&gt;Create data source-managed recording rules&lt;/h1&gt;
&lt;p&gt;
    &lt;a href=&#34;/docs/grafana/v11.4/alerting/alerting-rules/create-recording-rules/&#34;&gt;Recording rules&lt;/a&gt; allow you to periodically pre-compute frequently used or computationally expensive queries, saving the results as a new time series metric.&lt;/p&gt;
&lt;p&gt;Alert rules and dashboards can then query the new metric resulting from the recording rule. This is faster than querying real-time data and can help to reduce system load.&lt;/p&gt;
&lt;p&gt;Data source-managed recording rules can query Prometheus-based data sources like Mimir or Loki. For more information on recording rules in Prometheus, 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 in Prometheus&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Note that in data source-managed groups, the alert rules and recording rules within the same evaluation group are evaluated sequentially. This is useful to ensure that a recording rule is evaluated before any other alert rule queries the pre-computed metric.&lt;/p&gt;
&lt;h2 id=&#34;before-you-begin&#34;&gt;Before you begin&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Verify that you have write permission to the Prometheus or Loki data source. Otherwise, you will not be able to create or update Grafana Mimir managed alerting rules.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;For Grafana Mimir and Loki data sources, enable the ruler API by configuring their respective services.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Loki&lt;/strong&gt; - The &lt;code&gt;local&lt;/code&gt; rule storage type, default for the Loki data source, supports only viewing of rules. To edit rules, configure one of the other rule storage types.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Mimir&lt;/strong&gt; - use the &lt;code&gt;/prometheus&lt;/code&gt; prefix. The Prometheus data source supports both Grafana Mimir and Prometheus, and Grafana expects that both the &lt;a href=&#34;/docs/mimir/latest/operators-guide/reference-http-api/#querier--query-frontend&#34;&gt;Query API&lt;/a&gt; and &lt;a href=&#34;/docs/mimir/latest/operators-guide/reference-http-api/#ruler&#34;&gt;Ruler API&lt;/a&gt; are under the same URL. You cannot provide a separate URL for the Ruler API.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;add-new-recording-rule&#34;&gt;Add new recording rule&lt;/h2&gt;
&lt;p&gt;To create a new data source-managed recording rule:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Click &lt;strong&gt;Alerts &amp;amp; IRM&lt;/strong&gt; -&amp;gt; &lt;strong&gt;Alerting&lt;/strong&gt; -&amp;gt; &lt;strong&gt;Alert rules&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Scroll to the &lt;strong&gt;Data source-managed section&lt;/strong&gt; and click &lt;strong&gt;&#43;New recording rule&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;enter-recording-rule-name&#34;&gt;Enter recording rule name&lt;/h2&gt;
&lt;p&gt;The recording rule name must be a Prometheus metric name and contain no whitespace.&lt;/p&gt;
&lt;h2 id=&#34;define-recording-rule&#34;&gt;Define recording rule&lt;/h2&gt;
&lt;p&gt;Select your data source and enter a query. The queries used in data source-managed recording rules always run as instant queries.&lt;/p&gt;
&lt;h2 id=&#34;add-namespace-and-group&#34;&gt;Add namespace and group&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;From the &lt;strong&gt;Namespace&lt;/strong&gt; dropdown, select an existing rule namespace or add a new one.&lt;/p&gt;
&lt;p&gt;Namespaces can contain one or more rule groups and only have an organizational purpose.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;From the &lt;strong&gt;Group&lt;/strong&gt; dropdown, select an existing group within the selected namespace or add a new one.&lt;/p&gt;
&lt;p&gt;Rules within a group are run sequentially at a regular interval, with the same evaluation time.&lt;/p&gt;
&lt;p&gt;Newly created rules are appended to the end of the group, and you can reorder them from the &lt;strong&gt;Alert rules&lt;/strong&gt; page.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;add-labels&#34;&gt;Add labels&lt;/h2&gt;
&lt;p&gt;Optionally, you can add custom labels to the resulting metric by selecting existing key-value pairs from the drop down or entering the new key or value.&lt;/p&gt;
&lt;h2 id=&#34;query-the-new-metric-in-dashboards-or-alert-rules&#34;&gt;Query the new metric in dashboards or alert rules&lt;/h2&gt;
&lt;p&gt;Click &lt;strong&gt;Save rule&lt;/strong&gt; or &lt;strong&gt;Save rule and exit&lt;/strong&gt; to save the rule.&lt;/p&gt;
&lt;p&gt;Once saved, the new recording metric is available for use in dashboards and alert rules.&lt;/p&gt;
]]></content><description>&lt;h1 id="create-data-source-managed-recording-rules">Create data source-managed recording rules&lt;/h1>
&lt;p>
&lt;a href="/docs/grafana/v11.4/alerting/alerting-rules/create-recording-rules/">Recording rules&lt;/a> allow you to periodically pre-compute frequently used or computationally expensive queries, saving the results as a new time series metric.&lt;/p></description></item></channel></rss>