<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Alert rules on Grafana Labs</title><link>https://grafana.com/docs/grafana/v12.4/alerting/fundamentals/alert-rules/</link><description>Recent content in Alert rules on Grafana Labs</description><generator>Hugo -- gohugo.io</generator><language>en</language><atom:link href="/docs/grafana/v12.4/alerting/fundamentals/alert-rules/index.xml" rel="self" type="application/rss+xml"/><item><title>Queries and conditions</title><link>https://grafana.com/docs/grafana/v12.4/alerting/fundamentals/alert-rules/queries-conditions/</link><pubDate>Fri, 03 Apr 2026 19:43:06 +0000</pubDate><guid>https://grafana.com/docs/grafana/v12.4/alerting/fundamentals/alert-rules/queries-conditions/</guid><content><![CDATA[&lt;h1 id=&#34;queries-and-conditions&#34;&gt;Queries and conditions&lt;/h1&gt;
&lt;p&gt;In Grafana, queries fetch and transform data from data sources, which include databases like MySQL or PostgreSQL, time series databases like Prometheus or InfluxDB, and services like Amazon CloudWatch or Azure Monitor.&lt;/p&gt;
&lt;p&gt;An alert rule defines the following components:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A &lt;a href=&#34;#data-source-queries&#34;&gt;query&lt;/a&gt; that specifies the data to retrieve from a data source, with the syntax depending on the type of data source used.&lt;/li&gt;
&lt;li&gt;A &lt;a href=&#34;#alert-condition&#34;&gt;condition&lt;/a&gt; that must be met before the alert rule fires.&lt;/li&gt;
&lt;li&gt;Optional &lt;a href=&#34;#advanced-options-expressions&#34;&gt;expressions&lt;/a&gt; to perform transformations on the retrieved data.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Alerting periodically runs the queries and expressions, evaluating the condition. If the condition is breached, an alert instance is triggered for each time series.&lt;/p&gt;
&lt;h2 id=&#34;data-source-queries&#34;&gt;Data source queries&lt;/h2&gt;
&lt;p&gt;Alerting queries are the same as the queries used in Grafana panels, but Grafana-managed alerts are limited to querying &lt;a href=&#34;/grafana/plugins/data-source-plugins/?features=alerting&#34;&gt;data sources that have Alerting enabled&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Queries in Grafana can be applied in various ways, depending on the data source and query language being used. Each data source’s query editor provides a customized user interface to help you write queries that take advantage of its unique capabilities. For details about query editors and syntax in Grafana, refer to 
    &lt;a href=&#34;/docs/grafana/v12.4/panels-visualizations/query-transform-data/&#34;&gt;Query and transform data&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Alerting can work with two types of data:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Time series data&lt;/strong&gt; — The query returns a collection of time series, where each series must be &lt;a href=&#34;#reduce&#34;&gt;reduced&lt;/a&gt; to a single numeric value for evaluating the alert condition.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Tabular data&lt;/strong&gt; — The query must return data in a table format with only one numeric column. Each row must have a value in that column, used to evaluate the alert condition. See a 
    &lt;a href=&#34;/docs/grafana/v12.4/alerting/best-practices/table-data/&#34;&gt;tabular data example&lt;/a&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Each time series or table row is evaluated as a separate 
    &lt;a href=&#34;/docs/grafana/v12.4/alerting/fundamentals/#alert-instances&#34;&gt;alert instance&lt;/a&gt;.&lt;/p&gt;
&lt;figure
    class=&#34;figure-wrapper figure-wrapper__lightbox w-100p &#34;
    style=&#34;max-width: 750px;&#34;
    itemprop=&#34;associatedMedia&#34;
    itemscope=&#34;&#34;
    itemtype=&#34;http://schema.org/ImageObject&#34;
  &gt;&lt;a
        class=&#34;lightbox-link captioned&#34;
        href=&#34;/media/docs/alerting/alerting-query-conditions-default-options.png&#34;
        itemprop=&#34;contentUrl&#34;
      &gt;&lt;div class=&#34;img-wrapper w-100p h-auto&#34;&gt;&lt;img
          class=&#34;lazyload mb-0&#34;
          data-src=&#34;/media/docs/alerting/alerting-query-conditions-default-options.png&#34;data-srcset=&#34;/media/docs/alerting/alerting-query-conditions-default-options.png?w=320 320w, /media/docs/alerting/alerting-query-conditions-default-options.png?w=550 550w, /media/docs/alerting/alerting-query-conditions-default-options.png?w=750 750w, /media/docs/alerting/alerting-query-conditions-default-options.png?w=900 900w, /media/docs/alerting/alerting-query-conditions-default-options.png?w=1040 1040w, /media/docs/alerting/alerting-query-conditions-default-options.png?w=1240 1240w, /media/docs/alerting/alerting-query-conditions-default-options.png?w=1920 1920w&#34;data-sizes=&#34;auto&#34;alt=&#34;Alert query using the Prometheus query editor and alert condition&#34;width=&#34;2146&#34;height=&#34;792&#34;title=&#34;Alert query using the Prometheus query editor and alert condition&#34;/&gt;
        &lt;noscript&gt;
          &lt;img
            src=&#34;/media/docs/alerting/alerting-query-conditions-default-options.png&#34;
            alt=&#34;Alert query using the Prometheus query editor and alert condition&#34;width=&#34;2146&#34;height=&#34;792&#34;title=&#34;Alert query using the Prometheus query editor and alert condition&#34;/&gt;
        &lt;/noscript&gt;&lt;/div&gt;&lt;figcaption class=&#34;w-100p caption text-gray-13  &#34;&gt;Alert query using the Prometheus query editor and alert condition&lt;/figcaption&gt;&lt;/a&gt;&lt;/figure&gt;
&lt;h2 id=&#34;alert-condition&#34;&gt;Alert condition&lt;/h2&gt;
&lt;p&gt;The alert condition is the query or expression that determines whether the alert fires or not depending whether the value satisfies the specified comparison. There can be only one condition which determines the triggering of the alert.&lt;/p&gt;
&lt;p&gt;If the queried data meets the defined condition, Grafana fires the alert.&lt;/p&gt;
&lt;p&gt;When using &lt;strong&gt;Default options&lt;/strong&gt;, the &lt;code&gt;When&lt;/code&gt; input &lt;a href=&#34;#reduce&#34;&gt;reduces the query data&lt;/a&gt;, and the last input defines the threshold condition.&lt;/p&gt;
&lt;p&gt;When using &lt;strong&gt;Advanced options&lt;/strong&gt;, you have to choose one of your queries or expressions as the alert condition.&lt;/p&gt;
&lt;h2 id=&#34;advanced-options-expressions&#34;&gt;Advanced options: Expressions&lt;/h2&gt;
&lt;p&gt;Expressions are only available for Grafana-managed alerts and when the &lt;strong&gt;Advanced options&lt;/strong&gt; are enabled.&lt;/p&gt;
&lt;p&gt;In Grafana, expressions allow you to perform calculations, transformations, or aggregations on queried data. They modify existing metrics through mathematical operations, functions, or logical expressions.&lt;/p&gt;
&lt;p&gt;With expression queries, you can perform tasks such as calculating the percentage change between two values, applying functions like logarithmic or trigonometric functions, aggregating data over specific time ranges or dimensions, and implementing conditional logic to handle different scenarios.&lt;/p&gt;
&lt;figure
    class=&#34;figure-wrapper figure-wrapper__lightbox w-100p &#34;
    style=&#34;max-width: 750px;&#34;
    itemprop=&#34;associatedMedia&#34;
    itemscope=&#34;&#34;
    itemtype=&#34;http://schema.org/ImageObject&#34;
  &gt;&lt;a
        class=&#34;lightbox-link captioned&#34;
        href=&#34;/media/docs/alerting/alert-rule-expressions.png&#34;
        itemprop=&#34;contentUrl&#34;
      &gt;&lt;div class=&#34;img-wrapper w-100p h-auto&#34;&gt;&lt;img
          class=&#34;lazyload mb-0&#34;
          data-src=&#34;/media/docs/alerting/alert-rule-expressions.png&#34;data-srcset=&#34;/media/docs/alerting/alert-rule-expressions.png?w=320 320w, /media/docs/alerting/alert-rule-expressions.png?w=550 550w, /media/docs/alerting/alert-rule-expressions.png?w=750 750w, /media/docs/alerting/alert-rule-expressions.png?w=900 900w, /media/docs/alerting/alert-rule-expressions.png?w=1040 1040w, /media/docs/alerting/alert-rule-expressions.png?w=1240 1240w, /media/docs/alerting/alert-rule-expressions.png?w=1920 1920w&#34;data-sizes=&#34;auto&#34;alt=&#34;Alert rule expressions&#34;width=&#34;2392&#34;height=&#34;660&#34;title=&#34;Alert rule expressions&#34;/&gt;
        &lt;noscript&gt;
          &lt;img
            src=&#34;/media/docs/alerting/alert-rule-expressions.png&#34;
            alt=&#34;Alert rule expressions&#34;width=&#34;2392&#34;height=&#34;660&#34;title=&#34;Alert rule expressions&#34;/&gt;
        &lt;/noscript&gt;&lt;/div&gt;&lt;figcaption class=&#34;w-100p caption text-gray-13  &#34;&gt;Alert rule expressions&lt;/figcaption&gt;&lt;/a&gt;&lt;/figure&gt;
&lt;p&gt;The following expressions are available:&lt;/p&gt;
&lt;h3 id=&#34;reduce&#34;&gt;Reduce&lt;/h3&gt;
&lt;p&gt;Aggregates time series values within the selected time range into a single number.&lt;/p&gt;
&lt;p&gt;Reduce takes one or more time series and transform each series into a single number, which can then be compared in the alert condition.&lt;/p&gt;
&lt;p&gt;The following aggregations functions are included: &lt;code&gt;Min&lt;/code&gt;, &lt;code&gt;Max&lt;/code&gt;, &lt;code&gt;Mean&lt;/code&gt;, &lt;code&gt;Median&lt;/code&gt;, &lt;code&gt;Sum&lt;/code&gt;, &lt;code&gt;Count&lt;/code&gt;, and &lt;code&gt;Last&lt;/code&gt;. For more details, refer to the 
    &lt;a href=&#34;/docs/grafana/v12.4/panels-visualizations/query-transform-data/expression-queries/#reduce&#34;&gt;Reduce documentation&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&#34;math&#34;&gt;Math&lt;/h3&gt;
&lt;p&gt;Performs free-form math functions/operations on time series data and numbers. For example, &lt;code&gt;$A &#43; 1&lt;/code&gt; or &lt;code&gt;$A * 100&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;If queries being compared have &lt;strong&gt;multiple series in their results&lt;/strong&gt;, series from different queries are matched(joined) if they have the same labels. For example:&lt;/p&gt;


&lt;div data-shared=&#34;alerts/math-example.md&#34;&gt;
            &lt;ul&gt;
&lt;li&gt;&lt;code&gt;$A&lt;/code&gt; returns series &lt;code&gt;{host=&amp;quot;web01&amp;quot;} 30&lt;/code&gt; and &lt;code&gt;{host=&amp;quot;web02&amp;quot;} 20&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;$B&lt;/code&gt; returns series &lt;code&gt;{host=&amp;quot;web01&amp;quot;} 10&lt;/code&gt; and &lt;code&gt;{host=&amp;quot;web02&amp;quot;} 0&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;$A &#43; $B&lt;/code&gt; returns &lt;code&gt;{host=&amp;quot;web01&amp;quot;} 40&lt;/code&gt; and &lt;code&gt;{host=&amp;quot;web02&amp;quot;} 20&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;

        
&lt;p&gt;In this case, only series with matching labels are joined, and the operation is calculated between them.&lt;/p&gt;
&lt;p&gt;For additional scenarios on how Math handles different data types, refer to the 
    &lt;a href=&#34;/docs/grafana/v12.4/panels-visualizations/query-transform-data/expression-queries/#math&#34;&gt;Math documentation&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;You can also use a Math expression to define the &lt;strong&gt;alert condition&lt;/strong&gt;. For example:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;$B &amp;gt; 70&lt;/code&gt; should fire if the value of B (query or expression) is more than 70.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;$B &amp;lt; $C * 100&lt;/code&gt; should fire if the value of B is less than the value of C multiplied by 100.&lt;/li&gt;
&lt;li&gt;Compare matching series from two queries, as shown in the 
    &lt;a href=&#34;/docs/grafana/v12.4/alerting/best-practices/dynamic-thresholds/&#34;&gt;dynamic threshold example&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;resample&#34;&gt;Resample&lt;/h3&gt;
&lt;p&gt;Realigns a time range to a new set of timestamps, this is useful when comparing time series data from different data sources where the timestamps would otherwise not align.&lt;/p&gt;
&lt;p&gt;For more details, refer to the 
    &lt;a href=&#34;/docs/grafana/v12.4/panels-visualizations/query-transform-data/expression-queries/#resample&#34;&gt;Resample documentation&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&#34;threshold&#34;&gt;Threshold&lt;/h3&gt;
&lt;p&gt;Compares single numbers from previous queries or expressions (e.g., &lt;code&gt;$A&lt;/code&gt;, &lt;code&gt;$B&lt;/code&gt;) to a specified condition. It&amp;rsquo;s often used to define the alert condition.&lt;/p&gt;
&lt;p&gt;The threshold expression allows the comparison between two single values. Available threshold functions are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Is above&lt;/strong&gt;: &lt;code&gt;$A &amp;gt; 5&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Is below&lt;/strong&gt;: &lt;code&gt;$B &amp;lt; 3&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Is equal to&lt;/strong&gt;: &lt;code&gt;$A == 2&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Is not equal to&lt;/strong&gt;: &lt;code&gt;$B =! 4&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Is above or equal to&lt;/strong&gt;: &lt;code&gt;$A &amp;gt;= 8&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Is below or equal to&lt;/strong&gt;: &lt;code&gt;$B &amp;lt;= 16&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Is within range&lt;/strong&gt;: &lt;code&gt;$A &amp;gt; 0 AND $A &amp;lt; 10&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Is outside range&lt;/strong&gt;: &lt;code&gt;$B &amp;lt; 0 OR $B &amp;gt; 100&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Is within range included&lt;/strong&gt;: &lt;code&gt;$A &amp;gt;= 0 AND $A &amp;lt;= 10&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Is outside range included&lt;/strong&gt;: &lt;code&gt;$B &amp;lt;= 0 OR $B &amp;gt;= 100&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;A threshold returns &lt;code&gt;0&lt;/code&gt; when the condition is false and &lt;code&gt;1&lt;/code&gt; when true.&lt;/p&gt;
&lt;p&gt;If the threshold is set as the alert condition, the alert fires when the threshold returns &lt;code&gt;1&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id=&#34;recovery-threshold&#34;&gt;Recovery threshold&lt;/h3&gt;
&lt;p&gt;To reduce the noise from flapping alerts, you can set a recovery threshold so that the alert returns to the &lt;code&gt;Normal&lt;/code&gt; or &lt;code&gt;Recovering&lt;/code&gt; state only after the recovery threshold is crossed.&lt;/p&gt;
&lt;p&gt;Flapping alerts occur when the query value repeatedly crosses above and below the alert threshold, causing frequent state changes. This results in a series of firing-resolved-firing notifications and a noisy alert state history.&lt;/p&gt;
&lt;p&gt;For example, if you have an alert for latency with a threshold of 1000ms and the number fluctuates around 1000 (say 980 -&amp;gt; 1010 -&amp;gt; 990 -&amp;gt; 1020, and so on), then each of those might trigger a notification:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;980 -&amp;gt; 1010 triggers a firing alert.&lt;/li&gt;
&lt;li&gt;1010 -&amp;gt; 990 triggers a resolving alert.&lt;/li&gt;
&lt;li&gt;990 -&amp;gt; 1020 triggers a firing alert again.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To prevent this, you can set a recovery threshold to define two thresholds instead of one:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;An alert transitions to the &lt;code&gt;Pending&lt;/code&gt; or &lt;code&gt;Alerting&lt;/code&gt; state when it crosses the alert threshold.&lt;/li&gt;
&lt;li&gt;It then transitions to the &lt;code&gt;Recovering&lt;/code&gt; or &lt;code&gt;Normal&lt;/code&gt; state only when it crosses the recovery threshold.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;In the previous example, setting the recovery threshold to 900ms means the alert only resolves when the latency falls below 900ms:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;980 -&amp;gt; 1010 triggers a firing alert.&lt;/li&gt;
&lt;li&gt;1010 -&amp;gt; 990 does not resolve the alert, keeping it in the firing state.&lt;/li&gt;
&lt;li&gt;990 -&amp;gt; 1020 keeps the alert in the firing state.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The recovery threshold mitigates unnecessary alert state changes and reduces alert noise.&lt;/p&gt;
&lt;div class=&#34;collapse&#34; x-data=&#34;app_collapse()&#34;&gt;
  &lt;button class=&#34;collapse-trigger&#34; @click=&#34;toggle()&#34;&gt;
    &lt;span class=&#34;body-large&#34;&gt;Classic condition (legacy)&lt;/span&gt;
    &lt;span class=&#34;collapse-trigger__icon&#34; :class=&#34;{ &#39;collapse-trigger__icon-open&#39; : open }&#34;&gt;
      
  &lt;svg width=&#34;27&#34; height=&#34;26&#34; viewBox=&#34;0 0 27 26&#34; fill=&#34;none&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;
&lt;path opacity=&#34;0.2&#34; d=&#34;M1.73047 12.8359C1.73047 19.4634 7.10305 24.8359 13.7305 24.8359C20.3579 24.8359 25.7305 19.4634 25.7305 12.8359C25.7305 6.20852 20.3579 0.835937 13.7305 0.835937C7.10305 0.835937 1.73047 6.20852 1.73047 12.8359Z&#34; stroke=&#34;black&#34; stroke-width=&#34;1.5&#34; stroke-linecap=&#34;round&#34; stroke-linejoin=&#34;round&#34;/&gt;
&lt;path d=&#34;M18.2344 12.8359L9.23438 12.8359&#34; stroke=&#34;black&#34; stroke-width=&#34;1.5&#34; stroke-linecap=&#34;round&#34; stroke-linejoin=&#34;round&#34;/&gt;
&lt;path d=&#34;M13.7344 8.33594L13.7344 17.3359&#34; stroke=&#34;black&#34; stroke-width=&#34;1.5&#34; stroke-linecap=&#34;round&#34; stroke-linejoin=&#34;round&#34;/&gt;
&lt;/svg&gt;


    &lt;/span&gt;
  &lt;/button&gt;
  &lt;div class=&#34;collapse-content&#34; x-ref=&#34;content&#34; hidden=&#34;until-found&#34;&gt;
    &lt;div class=&#34;collapse-content__inner&#34; x-ref=&#34;content-inner&#34;&gt;&lt;h4 id=&#34;classic-condition-legacy&#34;&gt;Classic condition (legacy)&lt;/h4&gt;
&lt;p&gt;Classic conditions exist mainly for compatibility reasons and should be avoided if possible.&lt;/p&gt;
&lt;p&gt;Classic condition checks if any time series data matches the alert condition. It always produce one alert instance only, no matter how many time series meet the condition.&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Condition operators&lt;/th&gt;
              &lt;th&gt;How it works&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;and&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Two conditions before and after must be true for the overall condition to be true.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;or&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;If one of conditions before and after are true, the overall condition is true.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;logic-or&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;If the condition before &lt;code&gt;logic-or&lt;/code&gt; is true, the overall condition is immediately true, without evaluating subsequent conditions. For instance, &lt;code&gt;TRUE and TRUE logic-or FALSE and FALSE&lt;/code&gt; evaluate to &lt;code&gt;TRUE&lt;/code&gt;, because the preceding condition returns &lt;code&gt;TRUE&lt;/code&gt;.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;p&gt;The following aggregation functions are also available to further refine your query.&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Function&lt;/th&gt;
              &lt;th&gt;What it does&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;avg&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Displays the average of the values&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;min&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Displays the lowest value&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;max&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Displays the highest value&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;sum&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Displays the sum of all values&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;count&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Counts the number of values in the result&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;last&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Displays the last value&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;median&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Displays the median value&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;diff&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Displays the difference between the newest and oldest value&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;diff_abs&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Displays the absolute value of diff&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;percent_diff&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Displays the percentage value of the difference between newest and oldest value&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;percent_diff_abs&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Displays the absolute value of &lt;code&gt;percent_diff&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;count_non_null&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Displays a count of values in the result set that aren&amp;rsquo;t &lt;code&gt;null&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

]]></content><description>&lt;h1 id="queries-and-conditions">Queries and conditions&lt;/h1>
&lt;p>In Grafana, queries fetch and transform data from data sources, which include databases like MySQL or PostgreSQL, time series databases like Prometheus or InfluxDB, and services like Amazon CloudWatch or Azure Monitor.&lt;/p></description></item><item><title>Labels and annotations</title><link>https://grafana.com/docs/grafana/v12.4/alerting/fundamentals/alert-rules/annotation-label/</link><pubDate>Fri, 03 Apr 2026 19:43:06 +0000</pubDate><guid>https://grafana.com/docs/grafana/v12.4/alerting/fundamentals/alert-rules/annotation-label/</guid><content><![CDATA[&lt;h1 id=&#34;labels-and-annotations&#34;&gt;Labels and annotations&lt;/h1&gt;
&lt;p&gt;Labels and annotations add additional information about an alert using key/value pairs:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;#labels&#34;&gt;Labels&lt;/a&gt; are used to differentiate an alert from all other alerts and decide how to manage them.&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#annotations&#34;&gt;Annotations&lt;/a&gt; provide extra details for alert responders to help them understand and address potential issues.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;labels&#34;&gt;Labels&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Labels&lt;/strong&gt; are unique identifiers of an 
    &lt;a href=&#34;/docs/grafana/v12.4/alerting/fundamentals/#alert-instances&#34;&gt;alert instance&lt;/a&gt;. You can use them for searching, silencing, and routing notifications.&lt;/p&gt;
&lt;p&gt;Examples of labels are &lt;code&gt;server=server1&lt;/code&gt; or &lt;code&gt;team=backend&lt;/code&gt;. Each alert rule can have more than one label and the complete set of labels for an alert rule is called its label set. It is this label set that identifies the alert.&lt;/p&gt;


&lt;p&gt;For example, an alert instance might have the label set &lt;code&gt;{alertname=&amp;quot;High CPU usage&amp;quot;,server=&amp;quot;server1&amp;quot;}&lt;/code&gt; while another alert instance might have the label set &lt;code&gt;{alertname=&amp;quot;High CPU usage&amp;quot;,server=&amp;quot;server2&amp;quot;}&lt;/code&gt;. These are two separate alert instances because although their &lt;code&gt;alertname&lt;/code&gt; labels are the same, their &lt;code&gt;server&lt;/code&gt; labels are different.&lt;/p&gt;
&lt;figure
    class=&#34;figure-wrapper figure-wrapper__lightbox w-100p &#34;
    style=&#34;max-width: 2294px;&#34;
    itemprop=&#34;associatedMedia&#34;
    itemscope=&#34;&#34;
    itemtype=&#34;http://schema.org/ImageObject&#34;
  &gt;&lt;a
        class=&#34;lightbox-link&#34;
        href=&#34;/static/img/docs/alerting/unified/multi-dimensional-alert.png&#34;
        itemprop=&#34;contentUrl&#34;
      &gt;&lt;div class=&#34;img-wrapper w-100p h-auto&#34;&gt;&lt;img
          class=&#34;lazyload &#34;
          data-src=&#34;/static/img/docs/alerting/unified/multi-dimensional-alert.png&#34;data-srcset=&#34;/static/img/docs/alerting/unified/multi-dimensional-alert.png?w=320 320w, /static/img/docs/alerting/unified/multi-dimensional-alert.png?w=550 550w, /static/img/docs/alerting/unified/multi-dimensional-alert.png?w=750 750w, /static/img/docs/alerting/unified/multi-dimensional-alert.png?w=900 900w, /static/img/docs/alerting/unified/multi-dimensional-alert.png?w=1040 1040w, /static/img/docs/alerting/unified/multi-dimensional-alert.png?w=1240 1240w, /static/img/docs/alerting/unified/multi-dimensional-alert.png?w=1920 1920w&#34;data-sizes=&#34;auto&#34;alt=&#34;Image shows an example of an alert instance and the labels used on the alert instance.&#34;width=&#34;2294&#34;height=&#34;442&#34;/&gt;
        &lt;noscript&gt;
          &lt;img
            src=&#34;/static/img/docs/alerting/unified/multi-dimensional-alert.png&#34;
            alt=&#34;Image shows an example of an alert instance and the labels used on the alert instance.&#34;width=&#34;2294&#34;height=&#34;442&#34;/&gt;
        &lt;/noscript&gt;&lt;/div&gt;&lt;/a&gt;&lt;/figure&gt;
&lt;p&gt;Labels are a fundamental component of alerting:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The complete set of labels for an alert is what uniquely identifies an alert instance.&lt;/li&gt;
&lt;li&gt;The alerting UI shows labels for every alert instance generated during evaluation of that rule.&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/grafana/v12.4/alerting/fundamentals/notifications/notification-policies/&#34;&gt;Notification policies&lt;/a&gt; and 
    &lt;a href=&#34;/docs/grafana/v12.4/alerting/configure-notifications/create-silence/&#34;&gt;silences&lt;/a&gt; use labels to match alert instances and route them to contact points or stop their notifications.&lt;/li&gt;
&lt;li&gt;Contact points can include information from labels in notification messages.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;label-types&#34;&gt;Label types&lt;/h3&gt;
&lt;p&gt;An alert&amp;rsquo;s label set can contain three types of labels:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;User-configured labels&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Labels that you manually configure in the alert rule to identify the generated alert instances and manage the alerts. Common custom labels, depending on the use case, are: &lt;code&gt;severity&lt;/code&gt;, &lt;code&gt;priority&lt;/code&gt;, &lt;code&gt;team&lt;/code&gt;, and &lt;code&gt;service&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Additionally, you can use a 
    &lt;a href=&#34;/docs/grafana/v12.4/alerting/fundamentals/templates/&#34;&gt;template&lt;/a&gt; to customize the label value and generate dynamic values from query data.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Query labels&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Query labels are labels returned by the data source query.&lt;/p&gt;
&lt;figure
    class=&#34;figure-wrapper figure-wrapper__lightbox w-100p &#34;
    style=&#34;max-width: 1200px;&#34;
    itemprop=&#34;associatedMedia&#34;
    itemscope=&#34;&#34;
    itemtype=&#34;http://schema.org/ImageObject&#34;
  &gt;&lt;a
        class=&#34;lightbox-link captioned&#34;
        href=&#34;/media/docs/alerting/query-labels-and-values.png&#34;
        itemprop=&#34;contentUrl&#34;
      &gt;&lt;div class=&#34;img-wrapper w-100p h-auto&#34;&gt;&lt;img
          class=&#34;lazyload mb-0&#34;
          data-src=&#34;/media/docs/alerting/query-labels-and-values.png&#34;data-srcset=&#34;/media/docs/alerting/query-labels-and-values.png?w=320 320w, /media/docs/alerting/query-labels-and-values.png?w=550 550w, /media/docs/alerting/query-labels-and-values.png?w=750 750w, /media/docs/alerting/query-labels-and-values.png?w=900 900w, /media/docs/alerting/query-labels-and-values.png?w=1040 1040w, /media/docs/alerting/query-labels-and-values.png?w=1240 1240w, /media/docs/alerting/query-labels-and-values.png?w=1920 1920w&#34;data-sizes=&#34;auto&#34;alt=&#34;An alert rule query returning labels from the query.&#34;width=&#34;1275&#34;height=&#34;367&#34;title=&#34;An alert rule query returning labels from the query.&#34;/&gt;
        &lt;noscript&gt;
          &lt;img
            src=&#34;/media/docs/alerting/query-labels-and-values.png&#34;
            alt=&#34;An alert rule query returning labels from the query.&#34;width=&#34;1275&#34;height=&#34;367&#34;title=&#34;An alert rule query returning labels from the query.&#34;/&gt;
        &lt;/noscript&gt;&lt;/div&gt;&lt;figcaption class=&#34;w-100p caption text-gray-13  &#34;&gt;An alert rule query returning labels from the query.&lt;/figcaption&gt;&lt;/a&gt;&lt;/figure&gt;
&lt;p&gt;Query labels can generate multiple alert instances from the same alert rule, helping to distinguish alerts from different data. In this example, the &lt;code&gt;instance&lt;/code&gt; label generates an alert instance for each server.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Reserved labels&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Reserved labels are automatically added by Grafana:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;alertname&lt;/code&gt;: the name of the alert rule.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;grafana_folder&lt;/code&gt;: the title of the folder containing the alert.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Labels prefixed with &lt;code&gt;grafana_&lt;/code&gt; are reserved by Grafana for special use. You can disable reserved labels via the 
    &lt;a href=&#34;/docs/grafana/v12.4/setup-grafana/configure-grafana/#unified_alertingreserved_labels&#34;&gt;&lt;code&gt;unified_alerting.reserved_labels&lt;/code&gt;&lt;/a&gt; option.&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;Two alert rules cannot produce alert instances with the same labels. If two alert rules have the same labels such as &lt;code&gt;foo=bar,bar=baz&lt;/code&gt; and &lt;code&gt;foo=bar,bar=baz&lt;/code&gt; then one of the generated alert instances is discarded.&lt;/p&gt;
&lt;p&gt;Ensure the label set for an alert does not have two or more labels with the same name.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;If a configured label has the same name as a data source query label, it replaces the data source label.&lt;/li&gt;
&lt;li&gt;If a configured label has the same name as a reserved label, it is omitted.&lt;/li&gt;
&lt;/ul&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;div class=&#34;collapse&#34; x-data=&#34;app_collapse()&#34;&gt;
  &lt;button class=&#34;collapse-trigger&#34; @click=&#34;toggle()&#34;&gt;
    &lt;span class=&#34;body-large&#34;&gt;Label key format&lt;/span&gt;
    &lt;span class=&#34;collapse-trigger__icon&#34; :class=&#34;{ &#39;collapse-trigger__icon-open&#39; : open }&#34;&gt;
      
  &lt;svg width=&#34;27&#34; height=&#34;26&#34; viewBox=&#34;0 0 27 26&#34; fill=&#34;none&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;
&lt;path opacity=&#34;0.2&#34; d=&#34;M1.73047 12.8359C1.73047 19.4634 7.10305 24.8359 13.7305 24.8359C20.3579 24.8359 25.7305 19.4634 25.7305 12.8359C25.7305 6.20852 20.3579 0.835937 13.7305 0.835937C7.10305 0.835937 1.73047 6.20852 1.73047 12.8359Z&#34; stroke=&#34;black&#34; stroke-width=&#34;1.5&#34; stroke-linecap=&#34;round&#34; stroke-linejoin=&#34;round&#34;/&gt;
&lt;path d=&#34;M18.2344 12.8359L9.23438 12.8359&#34; stroke=&#34;black&#34; stroke-width=&#34;1.5&#34; stroke-linecap=&#34;round&#34; stroke-linejoin=&#34;round&#34;/&gt;
&lt;path d=&#34;M13.7344 8.33594L13.7344 17.3359&#34; stroke=&#34;black&#34; stroke-width=&#34;1.5&#34; stroke-linecap=&#34;round&#34; stroke-linejoin=&#34;round&#34;/&gt;
&lt;/svg&gt;


    &lt;/span&gt;
  &lt;/button&gt;
  &lt;div class=&#34;collapse-content&#34; x-ref=&#34;content&#34; hidden=&#34;until-found&#34;&gt;
    &lt;div class=&#34;collapse-content__inner&#34; x-ref=&#34;content-inner&#34;&gt;&lt;p&gt;Grafana has a built-in Alertmanager that supports both Unicode label keys and values. If you are using an external Prometheus Alertmanager, label keys must be compatible with their &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;data model&lt;/a&gt;.
This means that label keys must only contain &lt;em&gt;ASCII letters&lt;/em&gt;, &lt;em&gt;numbers&lt;/em&gt;, and &lt;em&gt;underscores&lt;/em&gt;.
Label keys must also be matched by the regular expression &lt;code&gt;[a-zA-Z_][a-zA-Z0-9_]*&lt;/code&gt;.
Any invalid characters are removed or replaced by the Grafana alerting engine before being sent to the external Alertmanager according to the following rules:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Whitespace is removed.&lt;/li&gt;
&lt;li&gt;ASCII characters are replaced with &lt;code&gt;_&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;All other characters are replaced with their lower-case hex representation.
If this is the first character it&amp;rsquo;s prefixed with &lt;code&gt;_&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Example: A label key/value pair &lt;code&gt;Alert! 🔔=&amp;quot;🔥&amp;quot;&lt;/code&gt; will become &lt;code&gt;Alert_0x1f514=&amp;quot;🔥&amp;quot;&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;If multiple label keys are sanitized to the same value, the duplicates have a short hash of the original label appended as a suffix.&lt;/p&gt;
&lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&#34;annotations&#34;&gt;Annotations&lt;/h2&gt;
&lt;p&gt;Annotations add additional information to alert instances, helping responders identify and address potential issues.&lt;/p&gt;
&lt;p&gt;Create clear and self-explanatory annotations so that first responders can investigate without needing deeper knowledge of the alert setup.&lt;/p&gt;
&lt;p&gt;Annotations are displayed in Grafana and are included by default in notifications. Grafana provides several optional annotations that you can edit:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;summary&lt;/code&gt;: A short summary of what the alert has detected and why.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;description&lt;/code&gt;: A detailed description of what happened and what the alert does.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;runbook_url&lt;/code&gt;: The runbook page to guide operators managing a potential incident.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;__dashboardUid__&lt;/code&gt; and &lt;code&gt;__panelId__&lt;/code&gt;: 
    &lt;a href=&#34;/docs/grafana/v12.4/alerting/alerting-rules/link-alert-rules-to-panels/&#34;&gt;Link the alert to a dashboard and panel&lt;/a&gt; to facilitate alert investigation.&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;For example, you can edit the annotation &lt;code&gt;summary&lt;/code&gt; to explain why the alert was triggered:&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;CPU usage has exceeded 80% for the last 5 minutes.&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;And edit the &lt;code&gt;description&lt;/code&gt; annotation to provide more context and how to respond:&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;The web server&amp;#39;s CPU has exceeded 80% for more than 5 minutes.

This indicates that the system is under heavy load and may result in an outage.

Consider scaling the server&amp;#39;s resources and investigating bottlenecks.&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Like labels, annotations can use a 
    &lt;a href=&#34;/docs/grafana/v12.4/alerting/fundamentals/templates/&#34;&gt;template&lt;/a&gt; to include dynamic data from queries.&lt;/p&gt;
]]></content><description>&lt;h1 id="labels-and-annotations">Labels and annotations&lt;/h1>
&lt;p>Labels and annotations add additional information about an alert using key/value pairs:&lt;/p>
&lt;ul>
&lt;li>&lt;a href="#labels">Labels&lt;/a> are used to differentiate an alert from all other alerts and decide how to manage them.&lt;/li>
&lt;li>&lt;a href="#annotations">Annotations&lt;/a> provide extra details for alert responders to help them understand and address potential issues.&lt;/li>
&lt;/ul>
&lt;h2 id="labels">Labels&lt;/h2>
&lt;p>&lt;strong>Labels&lt;/strong> are unique identifiers of an
&lt;a href="/docs/grafana/v12.4/alerting/fundamentals/#alert-instances">alert instance&lt;/a>. You can use them for searching, silencing, and routing notifications.&lt;/p></description></item></channel></rss>