Important: This documentation is about an older version. It's relevant only to the release noted, many of the features and functions have been updated or replaced. Please view the current version.
Annotations and labels help customize alert messages so that you can quickly identify the service or application that needs attention.
Annotations
Annotations are key-value pairs that provide additional meta-information about an alert. For example: a description, a summary, and runbook URL. These are displayed in rule and alert details in the UI and can be used in contact type message templates. Annotations can also be templated, for example Instance {{ $labels.instance }} down will have the evaluated instance label value added for every alert this rule produces.
Labels
Labels are key-value pairs that categorize or identify an alert. Labels are used to match alerts in silences or match and groups alerts in notification policies. Labels are also shown in rule or alert details in the UI and can be used in contact type message templates. For example, you can add a severity label, then configure a separate notification policy for each severity. You can also add, for example, a team label and configure notification policies specific to the team or silence all alerts for a particular team. Labels can also be templated like annotations, for example, {{ $labels.namespace }}/{{ $labels.job }} will produce a new rule label that will have the evaluated namespace and job label value added for every alert this rule produces. The rule labels take precedence over the labels produced by the query/condition.
The following template variables are available when expanding annotations and labels.
Name
Description
$labels
The labels from the query or condition. For example, {{ $labels.instance }} and {{ $labels.job }}. This is unavailable when the rule uses a classic condition.
$values
The values of all reduce and math expressions that were evaluated for this alert rule. For example, {{ $values.A }}, {{ $values.A.Labels }} and {{ $values.A.Value }} where A is the refID of the expression. This is unavailable when the rule uses a classic condition
$value
The value string of the alert instance. For example, [ var='A' labels={instance=foo} value=10 ].
Template functions
The following template functions are available when expanding annotations and labels.
Name
Argument
Return
Description
humanize
number or string
string
Converts a number to a more readable format, using metric prefixes.
humanize1024
number or string
string
Like humanize, but uses 1024 as the base rather than 1000.
humanizeDuration
number or string
string
Converts a duration in seconds to a more readable format.
humanizePercentage
number or string
string
Converts a ratio value to a fraction of 100.
humanizeTimestamp
number or string
string
Converts a Unix timestamp in seconds to a more readable format.
title
string
string
strings.Title, capitalises first character of each word.
toUpper
string
string
strings.ToUpper, converts all characters to upper case.
toLower
string
string
strings.ToLower, converts all characters to lower case.
match
pattern, text
boolean
regexp.MatchString Tests for a unanchored regexp match.