Labels
Labels are key/value pairs that become part of an alert’s identity. Alertmanager uses labels for routing, grouping, deduplication, and inhibition. To assign labels to an alert, include alabels block in the rule and add the relevant key/value pairs.
Example — adding severity labels to rule definitions:
Labels affect alert identity, deduplication, grouping, and routing in Alertmanager. Use them for any matching or routing logic.
Annotations
Annotations are intended for human-readable information included in notifications. They do not change an alert’s identity and therefore cannot be used for routing or matching in Alertmanager. Typical uses are descriptions, runbook links, and diagnostic hints. Annotations support templating using the Go template language. When writing templates, reference alert fields via thealert object. Because MDX and other processors can misinterpret template braces, always wrap template expressions in inline code or fenced code blocks.
Common template fields:
{{ .Labels }}— the full labels map{{ .Labels.instance }}— theinstancelabel value{{ .Value }}— the firing sample value (the metric value that caused the alert to fire)
description will be rendered with concrete values, for example:
filesystem /dev/sda3 on 10.0.0.5:9100 is low on space, current available space is 20.40345.
Remember: use
{{ .Labels }} (capital L) and {{ .Value }} (capital V) in templates. Labels are used by Alertmanager for routing; annotations are only for notification content and will not affect routing or matching.Labels vs Annotations — Quick Comparison
Best Practices
- Keep labels stable and meaningful (e.g.,
severity,team,service) so routing rules remain predictable. - Avoid putting large or frequently-changing text in labels — use annotations for verbose or dynamic content.
- Template annotations to include contextual details (
instance,device, metric value) so notifications are actionable. - Test templates with sample alerts to ensure correct rendering and escaping.
Links and References
- Alertmanager — Prometheus Alerting
- Prometheus Alerting Rules
- Go text/template package
- MDX Documentation