Create a Grafana Mimir or Loki managed recording rule
You can create and manage recording rules for an external Grafana Mimir or Loki instance. Recording rules calculate frequently needed expressions or computationally expensive expressions in advance and save the result as a new set of time series. Querying this new time series is faster, especially for dashboards since they query the same expression every time the dashboards refresh.
Before you begin
For Grafana Mimir and Loki data sources to work with Grafana 8.0 alerting, enable the ruler API by configuring their respective services.
Loki - The local
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.
Grafana Mimir - When configuring a Grafana Prometheus data source to point to Grafana Mimir, use the legacy /api/prom
prefix, not /prometheus
. Currently, we support only single-binary mode and you cannot provide a separate URL for the ruler API.
Note: If you do not want to manage alerting rules for a particular Loki or Prometheus data source, go to its settings page and clear the Manage alerts via Alerting UI checkbox.
Add a Grafana Mimir or Loki managed recording rule
- In the Grafana menu, click the Alerting (bell) icon to open the Alerting page listing existing alerts.
- Click New alert rule.
- In Step 1, add the rule name, type, and storage location.
- In Rule name, add a descriptive name. This name is displayed in the alert rule list. It is also the
alertname
label for every alert instance that is created from this rule. - From the Rule type drop-down, select Mimir / Loki managed alert.
- From the Select data source drop-down, select an external Prometheus, an external Loki, or a Grafana Cloud data source.
- From the Namespace drop-down, select an existing rule namespace. Otherwise, click Add new and enter a name to create a new one. Namespaces can contain one or more rule groups and only have an organizational purpose.
- From the Group drop-down, select an existing group within the selected namespace. Otherwise, click Add new and enter a name to create a new one. Newly created rules are appended to the end of the group. Rules within a group are run sequentially at a regular interval, with the same evaluation time.
- In Rule name, add a descriptive name. This name is displayed in the alert rule list. It is also the
- In Step 2, add the query to evaluate.
- In Step 3, add additional metadata associated with the rule.
- Add a description and summary to customize alert messages. Use the guidelines in Annotations and labels for alerting.
- Add Runbook URL, panel, dashboard, and alert IDs.
- Add custom labels.
- Click Save to save the rule or Save and exit to save the rule and go back to the Alerting page.
Related Grafana resources
Getting started with Grafana 8
Grafana 8.0 is here! Join us for a live walkthrough on how to get started using Grafana 8 and the Grafana 8 user interface while showing how to set up monitoring for a web service that uses Prometheus and Loki to store metrics and logs.
Unify your data with Grafana plugins: Splunk, MongoDB, Datadog, and more
Show how Grafana can be used to take data from multiple different sources and unify it, without disrupting the investments that are working today.
Getting started with Grafana Enterprise and observability
Join the Grafana Labs team for a 30-minute demo of how to get started with the Grafana Stack, so you can go from zero to observability in just a few minutes.