Monitoring and Alerting
Architecture Diagram
Formal Definitions
Detailed Explanation
Why Monitoring Matters
Without proper monitoring, you won't know about problems until users complain. Proactive monitoring helps you detect issues before they impact business operations.
Key Insight: The goal of monitoring is to answer three questions: What happened? Why did it happen? How do I fix it?
Monitoring Stack Components
| Component | Purpose | Tool Options |
|---|---|---|
| Metrics Collection | Gather performance data | StatsD, Prometheus |
| Visualization | Dashboards and graphs | Grafana, Kibana |
| Alerting | Notify on issues | Alertmanager, PagerDuty |
| Logging | Detailed execution logs | ELK Stack, Loki |
| Tracing | Track request flows | OpenTelemetry, Jaeger |
Critical Metrics to Monitor
| Metric | Warning Threshold | Critical Threshold | Impact |
|---|---|---|---|
| Scheduler Lag | > 60 seconds | > 300 seconds | Tasks delayed |
| Task Failure Rate | > 5% | > 10% | Data quality issues |
| Queue Depth | > 50 tasks | > 100 tasks | Resource exhaustion |
| Worker Memory | > 80% | > 95% | OOM kills |
| Database Connections | > 80% | > 95% | Connection failures |
Prometheus Configuration
Custom Metrics Implementation
Grafana Dashboard Configuration
{
"dashboard": {
"title": "Airflow Overview",
"panels": [
{
"title": "Task Success Rate",
"type": "stat",
"targets": [
{
"expr": "rate(airflow_task_success_total[5m]) / (rate(airflow_task_success_total[5m]) + rate(airflow_task_failure_total[5m]))",
"legendFormat": "Success Rate"
}
],
"thresholds": [
{"value": 0.95, "color": "green"},
{"value": 0.9, "color": "yellow"},
{"value": 0.8, "color": "red"}
]
},
{
"title": "Task Duration",
"type": "graph",
"targets": [
{
"expr": "histogram_quantile(0.95, rate(airflow_task_duration_seconds_bucket[5m]))",
"legendFormat": "P95 Duration"
}
]
},
{
"title": "Queue Depth",
"type": "graph",
"targets": [
{
"expr": "airflow_executor_queue_depth",
"legendFormat": "Queued Tasks"
}
]
},
{
"title": "Scheduler Lag",
"type": "stat",
"targets": [
{
"expr": "airflow_scheduler_lag_seconds",
"legendFormat": "Lag (seconds)"
}
],
"thresholds": [
{"value": 60, "color": "green"},
{"value": 300, "color": "yellow"},
{"value": 600, "color": "red"}
]
}
]
}
}
Alert Severity Levels
| Severity | Response Time | Escalation | Auto-resolve |
|---|---|---|---|
| Critical | 5 minutes | Immediate page | No |
| Warning | 30 minutes | 1 hour escalation | Possible |
| Info | Next business day | None | Yes |
Alert Best Practices
- Set meaningful thresholds â avoid alert fatigue from too many false positives
- Include context in alert messages â what failed, when, and impact
- Route alerts correctly â critical alerts to on-call, warnings to team channels
- Document runbooks â provide step-by-step resolution instructions
- Review alerts regularly â remove or adjust alerts that are no longer useful
Key Concepts Table
| Metric Category | Examples | Collection Method | Alert Threshold |
|---|---|---|---|
| Scheduler | Lag, parse time | StatsD/Prometheus | > 5min lag |
| Tasks | Success rate, duration | Callbacks | < 95% success |
| Queue | Depth, wait time | Database queries | > 100 queued |
| Resources | CPU, memory, disk | System metrics | > 85% utilization |
| Database | Query time, connections | SQLAlchemy | > 100ms query |
| SLA | Miss rate | SLA callbacks | Any SLA miss |
Code Examples
Alert Rules Configuration
# prometheus/alert_rules.yml
groups:
- name: airflow_alerts
rules:
- alert: AirflowSchedulerLagHigh
expr: airflow_scheduler_lag_seconds > 300
for: 5m
labels:
severity: warning
annotations:
summary: "Airflow scheduler lag is high"
description: "Scheduler lag is {{ $value }} seconds"
- alert: AirflowTaskFailureRateHigh
expr: rate(airflow_task_failure_total[5m]) / rate(airflow_task_total[5m]) > 0.05
for: 10m
labels:
severity: critical
annotations:
summary: "High task failure rate"
description: "Task failure rate is {{ $value | humanizePercentage }}"
- alert: AirflowQueueDepthHigh
expr: airflow_executor_queue_depth > 100
for: 15m
labels:
severity: warning
annotations:
summary: "High queue depth"
description: "{{ $value }} tasks queued"
- alert: AirflowDagRunStale
expr: time() - airflow_dag_run_last_scheduling_decision > 3600
for: 30m
labels:
severity: critical
annotations:
summary: "Stale DAG run detected"
description: "DAG run has not been scheduled for {{ $value }} seconds"
Slack Alerting Integration
Monitoring Dashboard Script
Performance Metrics
Key Performance Indicators
| KPI | Target | Warning | Critical |
|---|---|---|---|
| Task Success Rate | > 99% | 95-99% | < 95% |
| Scheduler Lag | < 60s | 60-300s | > 300s |
| Avg Task Duration | < 5min | 5-15min | > 15min |
| Queue Depth | < 50 | 50-100 | > 100 |
| MTTR | < 15min | 15-30min | > 30min |
| SLA Miss Rate | 0% | < 1% | > 1% |
Alert Distribution
| Severity | Response Time | Escalation | Auto-resolve |
|---|---|---|---|
| Critical | 5min | Immediate | No |
| Warning | 30min | 1 hour | Possible |
| Info | Next business day | None | Yes |
See Also
- Error Handling â Error tracking and recovery
- Performance Tuning â Performance optimization
- Kubernetes Executor â K8s-specific monitoring
- Multi-Tenancy â Tenant-level monitoring