Stage 6 · Operate
Dashboards with Grafana
Annotations and Events
Overlaying deploys, incidents, feature flags, and Kubernetes events on Grafana timelines.
Annotations Overview
Annotations are vertical markers on Grafana panels that show when events occurred. They help correlate metric changes with deployments, incidents, configuration changes, or any external event. Annotations turn dashboards from metric displays into investigation tools.
Annotation Sources
| Source | Use Case | How It Works |
|---|---|---|
| Dashboard UI | Manual annotations | Click on a panel to add a note |
| Prometheus alerts | Alert firing/resolving | Automatically annotates when alerts fire |
| Grafana API | Automated annotations | Push events from CI/CD pipelines |
| Loki queries | Log-based annotations | Annotate when specific log patterns match |
Prometheus-Based Annotations
Grafana can automatically create annotations when Prometheus alerts fire or resolve. Enable this by linking an Alertmanager datasource and selecting which alert rules should create annotations.
# In Grafana datasource config
apiVersion: 1
datasources:
- name: Alertmanager
type: alertmanager
url: http://alertmanager:9093
jsonData:
implementation: prometheusKubernetes Events
Kubernetes events show pod scheduling, scaling, restarts, and evictions. Overlaying these on Grafana dashboards reveals infrastructure-level changes that affect service metrics. Use kube-state-metrics or the events API to surface these events.
# Pod restart count increase
increase(kube_pod_container_status_restarts_total[1h]) > 0
# Pod not ready
kube_pod_status_ready{condition="false"} == 1Custom Annotations API
Push custom annotations using the Grafana API. This lets CI/CD pipelines mark deployments, feature flag services mark toggles, or any system mark important events directly on dashboards.
curl -X POST http://grafana:3000/api/annotations \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $API_KEY" \
-d '{
"dashboardUID": "my-dashboard",
"time": 1700000000000,
"text": "Deployed v2.3.1 to production",
"tags": ["deploy", "production"]
}'Use consistent tags like deploy, incident, or feature-flag on annotations. This lets you filter annotations in the dashboard UI and focus on specific event types during investigations.
Best Practices
- Automate annotations for all production deployments.
- Include the version, author, and change summary in annotation text.
- Use annotations to mark incident start and end times.
- Do not annotate every small change. Focus on events that affect user-facing behavior.
- Keep annotation text concise but informative for future reference.
Mark this lesson complete to store local progress and unlock a cleaner resume path the next time you visit.